微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何确定Angular中的上一页网址?

假设我当前在具有URL / user /:id的页面上。现在从这个页面我导航到下一页:id / posts。

现在有办法,以便我可以检查以前的URL是什么,即/ user /:id。

以下是我的路线

export const routes: Routes = [
  { 
    path: 'user/:id',component: UserProfileComponent
  },{  
    path: ':id/posts',component: UserPostsComponet 
  }
];
您可以订阅路线更改并存储当前事件,以便在下一次发生时使用它
prevIoUsUrl: string;
constructor(router: Router) {
  router.events
  .filter(event => event instanceof NavigationEnd)
  .subscribe(e => {
    console.log('prev:',this.prevIoUsUrl);
    this.prevIoUsUrl = e.url;
  });
}

另见How to detect a route change in Angular 2?

原文地址:https://www.jb51.cc/angularjs/144057.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐