Angular 2 routes current url with params

守給你的承諾、 提交于 2019-12-12 05:36:47

问题


I'm trying to use Angular 2 rc-4 with new Router.

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"
               }
      }
 ];

Then I subscribe to change route event. When event fires I want to find item from

appRoutes

The problem is with url with params:

Users/:id

I don't know how to compare it with current page url or how to ask RouterConfig.

Can you please help me?


回答1:


AS I found, best solution is to get current route using subscription to route change event. Based on this route you can get all data and check params. If you have better solution please add your answer too.



来源:https://stackoverflow.com/questions/38874655/angular-2-routes-current-url-with-params

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!