import { Router } from '@angular/router';
import { Injectable } from '@angular/core';
import {NavController} from '@ionic/angular';

@Injectable()
export class Transfer {
    constructor(private router: Router, private nc: NavController) {}

    transfer(req) {
        // 此处为ionic4路由跳转的时候不清空之前的页面组件造成的页面短暂交叠
        // ionic4在发生路由跳转的时候是先进行新组件的加载再进行旧组件的隐藏
        // 我没有找到相关的api以及解决办法,如果后面的人找到了的话麻烦将这个麻烦的方法给解决掉
        // if (document.getElementsByTagName('v' + req.url.replace(/\//, '-')).length > 0) {
        //     const y = <HTMLBodyElement>document.getElementsByTagName('v' + req.url.replace(/\//, '-'))[0];
        //     y.style.visibility = 'visible';
        // }
        // req.query = req.query ? req.query : {};
        // req.query.refresh = + new Date();
        // this.router.navigate([req.url], {queryParams: req.query, fragment: req.hash});
        // if (document.getElementsByTagName('v' + window.location.pathname.replace(/\//, '-')).length > 0) {
        //     const x = <HTMLBodyElement>document.getElementsByTagName('v' + window.location.pathname.replace(/\//, '-'))[0];
        //     x.style.visibility = 'hidden';
        //     setTimeout(() => {
        //         // 此处是防止移动端自己的back button跳转导致页面空白
        //         x.style.visibility = 'visible';
        //     }, 1000);
        // }
        if (!req.query) { req.query = ''; }
        this.nc.navigateRoot(req.url + req.query);
    }
}
