我在nativescript app中的一个延迟加载路由中使用children
路由时出现问题。当我尝试访问signin或注册时,我只是收到错误Cannot find primary outlet to load 'SigninComponent'
,这对我来说没有意义。
这是我的路由器模块:
const routes: Routes = [
{
path: '',
component: CompanyComponent,
children: [
{
path: 'signin',
loadChildren: 'routes/+company/routes/+signin/signin.module#SigninModule'
}
]
}
];
@NgModule({
imports: [NativeScriptRouterModule.forChild(routes)]
})
export class CompanyRouterModule {}
这是延迟加载的模块:
@NgModule({
imports: [
SharedModule,
CompanyRouterModule
],
exports: [CompanyRouterModule],
declarations: [CompanyComponent]
})
export class CompanyModule {}
最后CompanyComponent
的模板有一个出口:
<page-router-outlet></page-router-outlet>
为什么这不起作用?
修改
这是顶级路由配置,因此signin
路由可通过/company/signin
访问。
const routes: Routes = [
{
path: '',
loadChildren: './routes/+home/home.module#HomeModule'
},
{
path: 'company',
loadChildren: './routes/+company/company.module#CompanyModule'
}
];
@NgModule({
imports: [
NativeScriptRouterModule,
NativeScriptRouterModule.forRoot(routes),
],
exports: [
NativeScriptRouterModule
]
})
export class AppRouterModule {}