问题描述
我正尝试到达最开始或空白URL扩展名上的特定页面。就像我在本地运行项目一样,所以当我输入localhost:4200时,我想访问 localhost:4200 / pages / dashboard
|-App
|-Pages
|-dashboard
|-signIn
应用路由如下所示
const routes: Routes = [
{ path: '',redirectTo: '/pages/dashboard',pathMatch: 'full' },{ path: 'pages',loadChildren: './pages/pages.module#PagesModule',canActivate: [Authentication] },{ path: 'sign-in',component: SignInComponent }
];
export const routing: ModuleWithProviders = RouterModule.forRoot(routes,{
preloadingStrategy: PreloadAllModules,useHash: false
});
页面路由就像
export const routes: Routes = [
{
path: '',component: PagesComponent,children: [
{
path: 'dashboard',component: DashboardComponent,data: { breadcrumb: 'My Dashboard' },}
]
}
];
export const routing: ModuleWithProviders = RouterModule.forChild(routes);
App.module如下所示
imports: [
browserModule,HttpClientModule,ToastrModule.forRoot(),routing,PagesModule,SignInModule,],
解决方法
我遇到了同样的问题,我设法通过更改路由来使其工作
PagesModule.module.ts
-----------------------
export const routes: Routes = [
{
path: '',component: PagesComponent,data: { breadcrumb: 'My Dashboard' }
},{
path: 'dashboard',data: { breadcrumb: 'My Dashboard' }
}
}
];
export const routing: ModuleWithProviders = RouterModule.forChild(routes);
或尝试使用wildcard routes