是否可以使用此更新的angular-router将RouterConfig绑定到不同的组件?
例如,我的“app.components.ts”上有两个组件:
@Component({
template: require('./app.component.html'),
directives: [ ROUTER_DIRECTIVES ]
})此组件中的模板包括自定义视图装饰+子组件的路由器插座。
export const insideRoutes: RouterConfig = [
{ path: 'dashboard', component: DashboardComponent }
];并拥有自己的路由器,该路由器将在指定的路由上加载此组件。
我也有顶层组件:
@Component({
selector: 'app',
pipes: [],
providers: [ AppState ],
template: '<router-outlet></router-outlet>',
directives: [ ROUTER_DIRECTIVES ]
})该组件中的模板将只有自定义(登录)页面。
export const outsideRoutes: RouterConfig = [
{ path: 'login', component: LoginComponent }
)}我只想在上面的RouterConfig上使用路由来加载这个组件。
我尝试将两个路由器配置都包含在"app.routes.ts“中,如下所示:
export const appRouterProviders = [
provideRouter([outsideRoutes, insideRoutes])
];在main.browser.ts中将appRouterProviders链接到应用程序引导:
export function main(initialHmrState?: any): Promise<any> {
return bootstrap(AppComponent, [
...PROVIDERS,
...DIRECTIVES,
...PIPES,
...APP_PROVIDERS,
...ENV_PROVIDERS,
...HTTP_PROVIDERS,
appRouterProviders,
provide(LocationStrategy, { useClass: HashLocationStrategy })
]).catch(err => console.error(err));
}但是得到了路由器错误。
如果我只使用一个RouterConfig,就像这样:
export const appRouterProviders = [
provideRouter(outsideRoutes) // or insideRoutes
];它可以工作,但它只使用了我的根组件(顶层组件,它只有路由器出口。
至少我在"angular2: 2.0.0-beta.14“上找到了这个工作,用的是旧的,用的是@RouteConfig。
https://stackoverflow.com/questions/38392102
复制相似问题