Angular 5 子路由空路径覆盖根空路径?

Luk*_*ett 4 routing angular5

我尝试了以下设置。

根的路由:

const routes: Routes = [
    {path: 'home', loadChildren: 'app/home/home.module#HomeModule'},
    {path: 'note', loadChildren: 'app/note/note.module#NoteModule'},
    ...
    {path: '', redirectTo: 'home', pathMatch: 'full'},
    {path: '**', redirectTo: 'home', pathMatch: 'full'}
];

export const Routing: ModuleWithProviders = RouterModule.forRoot(routes);
Run Code Online (Sandbox Code Playgroud)

一个孩子的路由:

const routes: Routes = [
    {path: '', component: NoteContainerComponent},
    ...
];

export const NoteRouting: ModuleWithProviders = RouterModule.forChild(routes);
Run Code Online (Sandbox Code Playgroud)

因此,如果我导航到 localhost:4200,我希望被重定向到 localhost:4200/home 但没有发生 url 重定向,但已加载注释路由。如果我执行诸如 localhost:4200/note 之类的操作,空便笺路由不应该只匹配吗?子路由中的所有路由仅应在加载了子路由的父级时应用。

子路线上不可能有空路径吗?

Luk*_*ett 7

所以我终于找到了这个问题,我有我想在我的根模块中加载延迟导入的模块。这导致了问题,因为 RouterModule.forChild 被应用,因为它是 .forRoot