我在Stack Overflow上发现了很多路由问题,但不是我的问题的答案 . 用户登录后,用户将被路由到具有子路由的父级:
{
path: '',
component: LoginComponent,
},
{
path: 'parent',
component: ParentComponent,
children: [
{
// without this routing does not work
path: '',
redirectTo: 'parent'
},
{
path: 'child',
component: ChildComponent,
},
]
},
//... more routes
我的问题是没有 children
中提到的以下内容:
path: '',
redirectTo: 'parent'
用户不会从登录页面路由到父路由 . 但这也与我的网址混淆而不仅仅是
localhost:3000/parent
我得到 localhost:3000/parent/parent
. 那仍然显示正确的组件 . 但是当用户在其他地方导航时,会出现错误:
无法匹配任何路线:'something / something'
我该怎么解决这个问题,谢谢?
1 回答
导航到父组件时可能会导致您的网址出现问题,如果路径为
''
,在您的情况下为localhost:3000/parent
,然后你再次
redirectTo
parent
因此导致localhost:3000/parent/parent
尝试删除
redirectTo: 'parent'
,看看会发生什么!