我对angular2非常陌生,目前在路由方面遇到了一些奇怪的问题,特别是在延迟加载方面。
我的应用程序分为两个(更多的)布局,为此,我使用了两个组件( PublicComponent和SecureComponent )--这允许我加载完全不同的布局,并组织可伸缩的项目。
在我的路由设置中,我有两个问题:
我的程序-routing.module.ts:
const APP_ROUTES: Routes = [
{ path: '', redirectTo: '/home', pathMatch: 'full'},
{
path: '',
component: PublicComponent,
children: [
{ path: 'login', component: LoginComponent }
]
},
{
path: '',
component: SecureComponent,
canActivate: [LoggedInGuard],
children: [
{ path: 'home', component: HomeComponent },
{ path: 'customer', loadChildren: 'app/customer/customer.module#CustomerModule' }
]
}
];
@NgModule({
imports: [RouterModule.forRoot(APP_ROUTES)],
exports: [RouterModule]
})顾客-路由.模组:
export const CUSTOMER_ROUTES : Routes = [
{ path: '', component: CustomerListComponent },
{ path:'new', component: CustomerEditComponent },
{ path:'edit/:id', component: CustomerEditComponent }
];
@NgModule({
imports: [RouterModule.forChild(CUSTOMER_ROUTES)],
exports: [RouterModule]
})你知道我做错了什么吗?
发布于 2016-12-04 15:58:09
好吧,您用path:''添加了多条路径,这是错误的。想象一下,如果您的网站是www.localhost.com,对于这条路径,您已经将其分配给publicComponent和SecureComponent。
你的应用程序.module.ts应该是这样的.
const APP_ROUTES: Routes = [
{ path: '', redirectTo: 'loginmain', pathMatch: 'full'},
{
path: 'loginmain',
component: PublicComponent,
children: [
{ path: 'login', component: LoginComponent }
]
},
{
path: 'secure',
component: SecureComponent,
canActivate: [LoggedInGuard],
children: [
{ path: '', redirectTo:'home'},
{ path: 'home', component: HomeComponent },
{ path: 'customer', loadChildren: 'app/customer/customer.module#CustomerModule' }
]
}
];
@NgModule({
imports: [RouterModule.forRoot(APP_ROUTES)],
exports: [RouterModule]
})https://stackoverflow.com/questions/40958975
复制相似问题