角度 5 子路由空路径覆盖根空路径



我尝试了以下设置。

根目录的路由:

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);

一个孩子的路由:

const routes: Routes = [
    {path: '', component: NoteContainerComponent},
    ...
];
export const NoteRouting: ModuleWithProviders = RouterModule.forChild(routes);

因此,如果我导航到 localhost:4200,我希望被重定向到 localhost:4200/home,但相反,没有发生 url 重定向,但已加载注释路由。空笔记路由不应该只在我做类似 localhost:4200/note 时才匹配吗?仅当加载了子路由的父路由时,子路由中的所有路由才应适用。

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

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

最新更新