[英]Angular Routing - redirectTo child route without path
我尝试将子路由设置为在我输入站点地址时加载的默认路由。
const routes: Routes = [
{path: '', pathMatch: 'full', redirectTo: ''},
{
path: '', component: FrameDefaultComponent,
children: [
{path: '', component: SiteCalculatorComponent}
]
},
];
但这不起作用......当我给SiteCalculatorComponent
任何路由,如 calc 并从级别 1 重定向到'calc'
然后它就可以工作了。 我知道......但关键是我想在“没有”任何路径的情况下加载它;)
这可能吗? 如果是如何?
我有一个这样的路由器:
const firstRoutes: Routes = [ { path: '', children: [ { path: 'parent-url', children: secondRoutes } ] } ];
第二个是这样的:
export const secondRoutes: Routes = [ { path: '', children: [ { path: '', redirectTo: 'child-route', pathMatch: 'full' }, { path: 'child-route', component: ChildComponent } ] } ];
我的 ChildComponent 可以用 /child-route 或 /parent-url/child-route 调用。 我想禁用使用两个路由调用我的函数,因此设置只能使用 /parent-url/child-route 调用它。
我不知道如何检查是否有 /parent-url ,如果没有,则在没有 /parent-url 的情况下禁用调用 ChildComponent 。 在整个网址?
解决方案:
{
path: '', component: FrameDefaultComponent,
children: [
{path: '', component: SiteCalculatorComponent}
]
},
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.