的原因
嗨,我在我的应用中有此路线:
const routes : Routes = [
{path : '', redirectTo: '/login',pathMatch: 'full'},
{path: 'system', loadChildren: './system/system.module#SystemModule'},
{path:'**',component:NotFoundComponent}
];
@NgModule({
imports:[RouterModule.forRoot(routes,{
preloadingStrategy:PreloadAllModules
})],
exports:[RouterModule]
})
但是,当我运行应用程序时,它将路由找不到页面组件。
如果我在系统路由上尝试此操作:
const routes : Routes = [
{path:'',component:SystemComponent,canActivateChild:[AuthGuard],children:[
{path:'bill',component:BillPageComponent},
{path:'records',component:RecordsPageComponent},
{path:'planning',component:PlanningPageComponent},
{path:'history',component:HistoryPageComponent},
{path:'history/:id',component:HistoryDetailsComponent}
]},
{path:'**',component:NotFoundComponent}
];
@NgModule({
imports:[
RouterModule.forChild(routes)
],
exports: [RouterModule]
})
它可以正常工作,但在顶级路线上却没有。请建议。
你有
{path : '', redirectTo: '/login',pathMatch: 'full'}
对于默认路由。但是,login
路由未定义。这就是为什么您的应用程序被重定向到Notund Page
请在路由中添加/login
。因为它找不到登录路线。
const routes : Routes = [
{path : '', redirectTo: '/login',pathMatch: 'full'},
{path: 'login', loadChildren: './login/login.module#LoginModule'},
{path: 'system', loadChildren: './system/system.module#SystemModule'},
{path:'**',component:NotFoundComponent}
];