简体   繁体   English

Angular 2使用参数将当前URL路由

[英]Angular 2 routes current url with params

I'm trying to use Angular 2 rc-4 with new Router. 我正在尝试将Angular 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"
               }
      }
 ];

Then I subscribe to change route event. 然后,我订阅更改路线事件。 When event fires I want to find item from 事件触发时,我想从中查找项目

appRoutes

The problem is with url with params: 问题是带有参数的URL:

Users/:id

I don't know how to compare it with current page url or how to ask RouterConfig. 我不知道如何将其与当前页面网址进行比较,或者如何询问RouterConfig。

Can you please help me? 你能帮我么?

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. 如果您有更好的解决方案,请也添加您的答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM