-->

角2路当前的URL使用参数(Angular 2 routes current url with pa

2019-10-28 16:21发布

我试图用角2 RC-4新的路由器。

export const appRoutes:  
  RouterConfig =[
  {
    path: "",
    component: HomeComponent,
    terminal: true,
    data: {
            title: "Home"
          }
   },
   {
     path: "Users",
     component: UserListComponent,
     data: {
            title: "Users"
           }
      },
      {
        path: "Users/:id",
        component: UserEditComponent,
        data: {
              title: "Edit User"
               }
      }
 ];

然后我订阅改变航线的事件。 当事件触发我想从找项目

appRoutes

问题是与使用参数的URL:

Users/:id

我不知道如何将它与当前页面的URL或者怎么问RouterConfig比较。

你能帮我么?

Answer 1:

因为我发现,最好的解决办法是使用订阅路由变化事件来获得当前的路线。 根据这条路线,你可以得到的所有数据,并检查PARAMS。 如果你有更好的解决办法也请添加你的答案。



文章来源: Angular 2 routes current url with params