Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 返回到最后一页(模块),而不是最后一个状态_Angularjs_Typescript_Routing_Angular2 Routing_Aurelia - Fatal编程技术网

Angularjs 返回到最后一页(模块),而不是最后一个状态

Angularjs 返回到最后一页(模块),而不是最后一个状态,angularjs,typescript,routing,angular2-routing,aurelia,Angularjs,Typescript,Routing,Angular2 Routing,Aurelia,例如,在Typescript中,有没有办法获取最后一个模块而不是最后一个状态 如果有一条路线 从A页到B页, 内页B 从某个过程中,他添加了一些可选参数。 当单击“后退”按钮时,用户必须能够直接返回到A页,而无需前往B页的路线,无需可选参数此代码对我来说非常有用,可以访问最后一页的模块。请试一试 import { Router , NavigationEnd} from '@angular/router'; export class myComponent { private pr

例如,在Typescript中,有没有办法获取最后一个模块而不是最后一个状态 如果有一条路线 从A页到B页, 内页B 从某个过程中,他添加了一些可选参数。
当单击“后退”按钮时,用户必须能够直接返回到A页,而无需前往B页的路线,无需可选参数

此代码对我来说非常有用,可以访问最后一页的模块。请试一试

import { Router , NavigationEnd} from '@angular/router';

  export class myComponent {
    private previousUrl: string;

    constructor(private router: Router){

      router.events
         .filter(event => event instanceof NavigationEnd)
         .subscribe(e => {
            let path = this.previousUrl;
            if(path !="" && path!=undefined){
               let res = path.split("/");
               console.log(res[1]); /* here in res[1] you will get the last clicked page module url. Now you can route to last module using this res[1] value */
            }
         this.previousUrl = e.url;

      });
   }
 } 

希望这能有所帮助。

这实际上就是答案