Routing 角5子路由空路径覆盖根空路径?
我尝试了以下设置 根目录的路由:Routing 角5子路由空路径覆盖根空路径?,routing,angular5,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'}, {pa
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基本上,不要将import ChildModule(名称可以不同)导入到AppModule(根模块)中。