带孩子的角度路由问题

时间:2018-01-18 14:32:44

标签: angular

由于缺乏更好的解释词,lemme显示了我所做的一些代码以及我想要的代码:

这是我的app-routing.module.ts

const appRoutes: Routes = [   
    { path: '', component: LandingComponent,
    { path: 'myroute', loadChildren: './myroute/myroute.module#MyrouteModule' }
];

这是我的mymodule/mymodule.routing.ts

const routes: Routes = [
  { path: '', component: NavComponent, children: [
    { path: '', component: WelcomeComponent },
    { path: 'subroute', loadChildren: './subroute/subroute.module#SubrouteModule' },
  ] }
];

<router-outlet></router-outlet>

中有一个/myroute/nav.component.ts

最后,还有mymodule/subroute/subroute.routing.ts

const routes: Routes = [
    { path: '', component: SubrouteComponent },
    { path: 'subroute', component: SubrouteComponent }, 
];

所以这是对正确期望的精神图景:

localhost/匹配LandingComponent

localhost/myroute/匹配WelcomeComponent

localhost/myroute/subroute/匹配SubrouteComponent

考虑到上述情况,我应该要求,

localhost/subroute

它直接与SubrouteComponent匹配,但失败将其注入路由器插座,这是预期的。

匹配是因为匹配''mymodule.routing.ts subroute.routing.ts的{​​{1}},因此''有点泄漏。

现在,问题。有没有办法让SubrouteComponent仅在传入的URL符合规范时才能匹配?

那是/subroute的用途吗?如何实现?

0 个答案:

没有答案