我有以下通配符角通配符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