我尝试了以下设置。
根的路由:
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 之类的操作,空便笺路由不应该只匹配吗?子路由中的所有路由仅应在加载了子路由的父级时应用。
子路线上不可能有空路径吗?