返回最后一页(模块)而不是最后一个状态
route back to last page(module) instead of last status
在 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;
});
}
}
希望对您有所帮助。
在 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;
});
}
}
希望对您有所帮助。