小编Z3R*_*3R0的帖子

带参数的角路由redirectTo

我有角度布线问题。在我的应用中,我有一些这样的路线:

[{
     path: 'myroutes/:id',
     component: BarComponent
 }, {
     path: 'myroutes/:id/:value',
     component: FooComponent
 }]
Run Code Online (Sandbox Code Playgroud)

我想更改此路由,但是必须将旧路由重定向到新路由。所以我这样改变了我的代码:

[{
    path: 'myroutes/:id/:value',
    redirectTo: 'myroute/:id/:value'
}, {
    path: 'myroutes/:id',
    component: BarComponent
}, {
    path: 'myroute/:id/:value',
    component: FooComponent
}]
Run Code Online (Sandbox Code Playgroud)

通过此路由,我得到了NavigationError:

无法重定向到'/ myroute /:id /:value'。找不到':id'。

更改代码以在redirectTo路由中使用固定参数可以解决错误,但是参数必须是动态的。

路线是使用导入的RouterModule.forRoot()

希望这是足够的信息,否则请随时要求更多。;)

谢谢你的帮助!:)

angular angular-router

5
推荐指数
2
解决办法
4148
查看次数

标签 统计

angular ×1

angular-router ×1