我有以下通配符角通配符redirectTo不工作
const routes: Routes = [
{
path: '',
children: [
{
path: 'list/:id',
component: ListComponent
},
{
path: 'view/:id',
component: ViewComponent
},
{
path: 'edit/:id',
component: EditComponent
},
{
path: '**',
redirectTo: 'list/:id',
pathMatch: 'full'
}
]
}
];
的:id是,我需要从后端获取ID的占位符。通配符不起作用(不重定向我的列表组件),给我以下错误
EXCEPTION: Uncaught (in promise): Error: Cannot redirect to 'list/:id'. Cannot find ':id'.
Error: Cannot redirect to 'list/:id'. Cannot find ':id'.
。任何想法的家伙?提前致谢。
它给你的错误,因为你的通配符路由它找不到':id'的值。你可以做的是为你需要定义'component'的通配符路由,在'component'里面你可以从你的后端得到':id',并根据你的id从那个组件重定向到'list /:id'从后端返回 – ranakrunal9
是啊..但我们如何解决这个问题?或者我该如何将id传入路由器 – blackdaemon