似乎@ui-router/angular-hybrid
在初始加载/重新加载时无法识别在 ng2+ 模块中注册的路由。如果例如通过键入 url 进行导航,则相同的路线正在工作。
我遵循了来自@ui-router/angular-hybrid的官方升级文档
这是 ng2+AppModule
代码:
const states: NgHybridStateDeclaration[] = [
{
name: 'x',
url: '/x',
component: XComponent
}
];
enableProdMode();
@NgModule({
imports: [
BrowserModule,
UpgradeModule,
UIRouterUpgradeModule.forRoot({states: states}),
ComponentsModule,
DirectivesModule
],
declarations: [AppComponent],
exports: [],
entryComponents: [],
providers: [],
bootstrap: []
})
export class Ng2AppModule {
constructor(
@Inject(forwardRef(() => UpgradeModule)) private upgrade: UpgradeModule,
@Inject(forwardRef(() => Config)) private config: Config
) {}
ngDoBootstrap() {
this.upgrade.bootstrap(document as any, ['app'], { strictDi: true });
}
}
和引导逻辑:
AppModule.config([
'$urlServiceProvider',
($urlService: UrlService) => $urlService.deferIntercept()
]);
getConfig()
.then((config: Config) => {
console.log('CONFIG::::', config);
AppModule.constant('config', config);
setAngularLib(angular);
platformBrowserDynamic([
{
provide: Config,
useValue: config
}
])
.bootstrapModule(Ng2AppModule)
.then(platformRef => {
platformRef.injector.get<NgZone>(NgZone).run(() => {
const urlService = platformRef.injector.get(UIRouter).urlService;
urlService.listen();
urlService.sync();
});
downgradeSharedComponents(AppModule);
});
})
PS 现有的 angularjs 路由工作正常,问题出在 ng2+ 模块中注册的路由。
任何帮助表示赞赏,谢谢^^