繁体   English   中英

将空白路由到ID为的子组件

[英]Route blank to child component with id

我希望将www.mypage.com/users路由到www.mypage.com/users/1 ,如何实现?

我尝试了以下

 path: 'users', redirectTo: '1', pathMatch: 'full', children: [     
  { path: ':id', component: UsersComponent }
]

我也可以返回404页面,但是那不是我想要的。

这可以通过在子路径中添加另一个带有'' (空白)路径检查”的子路径来完成。 但是您必须创建一个父组件,该模板将再次具有router-outlet

{
  path: 'users', component: UserWrapperComponent, 
    children: [
       { path: '', redirectTo: '1', pathMatch: 'full' }
       { path: ':id', component: UsersComponent }
    ]
}

尝试这个,

{path: 'users', redirectTo: 'users/1', pathMatch: 'full', children: [     
  { path: '1', component: UsersComponent }
]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM