angular默认路由的默认路由
angular default route of default route
使用@angular/router 7.2.5,重定向到本身有默认路由的默认路由时,不会命中嵌套的默认路由。
换句话说,使用这个路由配置:
{ path: '', redirectTo: '/hello', pathMatch: 'full' },
{ path: 'hello', component: HelloComponent, children: [
{ path: '', redirectTo: 'child', pathMatch: 'full' },
{ path: 'child', component: ChildComponent }
]}
路由 /hello
将按预期重定向到 /hello/child
,但路由 /
将重定向到 /hello
而不是 /hello/child
。我错过了什么?
这个问题在 stackblitz 上得到了证明:https://stackblitz.com/edit/angular-3h3gt9
感谢您的帮助
删除父重定向路由中的 /
。 redirectTo:
必须与路由器中的路径匹配。它正在尝试匹配您没有的 /hello
。
{ path: '', redirectTo: 'hello', pathMatch: 'full' },
{ path: 'hello', component: HelloComponent, children: [
{ path: '', redirectTo: 'child', pathMatch: 'full' },
{ path: 'child', component: ChildComponent }
]}
使用@angular/router 7.2.5,重定向到本身有默认路由的默认路由时,不会命中嵌套的默认路由。
换句话说,使用这个路由配置:
{ path: '', redirectTo: '/hello', pathMatch: 'full' },
{ path: 'hello', component: HelloComponent, children: [
{ path: '', redirectTo: 'child', pathMatch: 'full' },
{ path: 'child', component: ChildComponent }
]}
路由 /hello
将按预期重定向到 /hello/child
,但路由 /
将重定向到 /hello
而不是 /hello/child
。我错过了什么?
这个问题在 stackblitz 上得到了证明:https://stackblitz.com/edit/angular-3h3gt9
感谢您的帮助
删除父重定向路由中的 /
。 redirectTo:
必须与路由器中的路径匹配。它正在尝试匹配您没有的 /hello
。
{ path: '', redirectTo: 'hello', pathMatch: 'full' },
{ path: 'hello', component: HelloComponent, children: [
{ path: '', redirectTo: 'child', pathMatch: 'full' },
{ path: 'child', component: ChildComponent }
]}