0

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?

Vladimir Rodchenko
  • 1,052
  • 15
  • 25
  • What do you want to compare with what? What is the problem? – Günter Zöchbauer Aug 10 '16 at 13:22
  • How to get current route from appRoutes? e.g. when I'm on page http://localhost:8080/Users/1 I want to get item { path: "Users/:id", component: UserEditComponent, data: { title: "Edit User" } } – Vladimir Rodchenko Aug 10 '16 at 13:24
  • In the new version (RC.5) you can get the router config of the current child router. I don't know yet if you can get the current route as well. In previous versions you can get the param or the data. You could encode some id or name in the data to derive the route from the data. – Günter Zöchbauer Aug 10 '16 at 13:28

1 Answers1

0

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.

Vladimir Rodchenko
  • 1,052
  • 15
  • 25