由于缺乏更好的解释词,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
的用途吗?如何实现?