angular如何处理两个参数不同的相似路由?
How does angular deal with two similar routes that have different parameters?
angular如何处理两个相似但参数不同的路由?
例如:
const routes: Routes = [
{
path: '',
component: HomeComponent
},
{
path: ':username',
component: UserComponent
},
{
path: ':username2',
component: HomeComponent2
}
];
angular 怎么知道或者你怎么告诉 angular 哪个参数是 username
哪个参数是 username2
?
它不能,它总是会转到 UserComponent
,因为这是它会找到的第一个匹配项。他们应该总是有一个可识别的路径部分:
{
path: 'user/:username',
component: UserComponent
},
{
path: 'home/:username2',
component: HomeComponent2
}
angular如何处理两个相似但参数不同的路由?
例如:
const routes: Routes = [
{
path: '',
component: HomeComponent
},
{
path: ':username',
component: UserComponent
},
{
path: ':username2',
component: HomeComponent2
}
];
angular 怎么知道或者你怎么告诉 angular 哪个参数是 username
哪个参数是 username2
?
它不能,它总是会转到 UserComponent
,因为这是它会找到的第一个匹配项。他们应该总是有一个可识别的路径部分:
{
path: 'user/:username',
component: UserComponent
},
{
path: 'home/:username2',
component: HomeComponent2
}