如何使用Angularjs 2中的参数进行多级路由

时间:2016-08-30 03:36:02

标签: angularjs routing

我无法使用router.navigate在Angular js 2中使用params实现多级路由。

这些是我的代码,只是一个子route.ts和一个组件使用导航,请注意我已经可以使用路径''和' manageDealers'这意味着这个route.ts是有效的

route.ts

export const dealerRoutes : Routes = [
  {
    path: 'dealers',
    children: [
      {
      path: '',
      redirectTo: 'manageDealers'
      },{
        path: 'manageDealers',
        component: DealerManage,
      },{
        path: ':dealerId/users/:userId',
        name: 'DealerUserDetailManage',
        component: DealerUserDetailManage,
      }
    ]
  }
]

component.ts

viewDetail(dealerId:number,userId:number){
    this.router.navigate([''DealerUserDetailManage',{dealerId: dealerId, userId: userId}]);
  }

没用?

1 个答案:

答案 0 :(得分:0)

编辑 route.ts 默认路由redirectTo也需要/。尝试这样的代码:

    export const dealerRoutes : Routes = [
  {
    path: 'dealers',
    children: [
      {
      path: '',
      redirectTo: '/manageDealers',
      pathMatch:'full'
      },{
        path: 'manageDealers',
        component: DealerManage,
      },{
        path: ':dealerId/users/:userId',
        name: 'DealerUserDetailManage',
        component: DealerUserDetailManage,
      }
    ]
  }
]