Javascript 在Angular2 NGmodule中,我想根据条件加载2组不同的路由模块
在Angular2中,我想为求职者和雇主加载2套不同的路线模块1。URL相同,但求职者和雇主的模块不同。因此,我想根据登录会话动态加载路由模块。有什么方法可以做到吗??还是有更好的方法可以在angular2中实现 基本上,我希望能够加载基于条件的模块 下面是示例代码Javascript 在Angular2 NGmodule中,我想根据条件加载2组不同的路由模块,javascript,angular,typescript,rxjs,Javascript,Angular,Typescript,Rxjs,在Angular2中,我想为求职者和雇主加载2套不同的路线模块1。URL相同,但求职者和雇主的模块不同。因此,我想根据登录会话动态加载路由模块。有什么方法可以做到吗??还是有更好的方法可以在angular2中实现 基本上,我希望能够加载基于条件的模块 下面是示例代码 @NgModule({ imports: [BrowserModule, HttpModule,customRoutes.getCustomRoutes(), SharedModule.forRoot()
@NgModule({
imports: [BrowserModule, HttpModule,customRoutes.getCustomRoutes(),
SharedModule.forRoot()],
declarations: [AppComponent],
providers: [
{
provide: APP_BASE_HREF,
useValue: '<%= APP_BASE %>' },
CanActivateGuard,AccountService, ProfileService],
bootstrap: [AppComponent]
})
export class AppModule {
constructor(private _http:Http,@Inject(AccountService) authService:AccountService) {
}
//但是getCustomRoutes需要是一个静态方法才能在NGModule中调用。但如果我将其设置为静态,我将获得对accountService对象的访问权
(是否有更好的方法实现基于用户会话加载不同路由的功能)不幸的是,目前不支持在运行时配置路由。当角度应用程序被引导时,路径是指定的,但之后不能更改它们。如果我想根据特定条件加载模块,这是可能的吗?如果设置了雇主会话,则我需要加载仅针对雇主的模块
export class customRoutes {
public customRoutes;
constructor(@Inject(AccountService) accountService:AccountService) {
}
getCustomRoutes() {
return this.customRoutes = (accountService.getCheckEmployer())?JobSeekerRoutes:EmployerRoutes;
}
}