[英]Angular wildcard redirectTo not working
I have the following wildcard 我有以下通配符
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'
}
]
}
];
the :id is a placeholder for the id that I need to get from backend. :id是我需要从后端获取的ID的占位符。 The wildcard is not working (not redirecting me the list component), giving me the following error
通配符不起作用(不重定向我的列表组件),给我以下错误
EXCEPTION: Uncaught (in promise): Error: Cannot redirect to 'list/:id'. Cannot find ':id'.
Error: Cannot redirect to 'list/:id'. Cannot find ':id'.
. 。 Any idea guys?
有想法吗? thanks in advance.
提前致谢。
How should the router know to WHICH list you want to navigate if the users enters ANY invalid route? 如果用户输入任何无效的路由,路由器如何知道要导航的WHICH列表?
Should that :id
be 0, 33 or even 1337? :id
应该是0、33还是1337? The router can not know! 路由器不知道!
Only possible way would be to define a fallback router without a parameter or define one: 唯一可能的方法是定义不带参数的后备路由器或定义一个:
{
path: '**',
redirectTo: 'list/77', // put your fallback-id here !!
pathMatch: 'full'
}
better would be to create a site like 404 error
. 最好是创建一个类似
404 error
的网站。 Show a message like page not found
and put some navigation options to the user.. maybe an overview of all list or whatever.. 显示
page not found
类的消息,并向用户显示一些导航选项。可能是所有列表的概述等等。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.