我目前正在使用Angular 2 - RC5與路由器3.0.0 RC1。這似乎是一個很常見的錯誤,但我找不到任何可行的解決方案。我的組件結構包含一個「BasicContentComponent」,其中包含主菜單和標題以及子路徑內容的輔助輸出口。 「BasicContentComponent」來自共享模塊,子路由該子路由的特定模塊的組件。Angular2 RC5 |路由器:無法匹配任何路由
我的路由配置看起來像這樣
export const routeConfig = [
{
path: 'home',
component: BasicContentComponent,
children: [
{
path: '',
component: HomeContainer,
//canActivate: [IsAuthenticatedGuard],
outlet: 'content', // REMOVE THIS LINE
//resolve: {
// homeState: HomeResolver
//}
}
]
}
];
如果我刪除了「兒童」的定義,我能夠裝載「/家」,但這個配置我得到的錯誤。
以下是模塊配置,因爲問題也可能存在。
app.module.ts
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
FormsModule,
HttpModule,
RouterModule.forRoot(routeConfig), //see above
SharedModule.forRoot(),
HomeModule
],
bootstrap: [AppComponent]
})
export class AppModule {}
shared.module.ts
import { Store, StoreModule } from '@ngrx/store';
@NgModule({
imports: [
RouterModule,
CommonModule,
...
StoreModule.provideStore(reducers),
],
declarations: [
BasicContentComponent,
...
],
exports: [BasicContentComponent, ...],
})
export class SharedModule {
static forRoot() : ModuleWithProviders {
return {
ngModule: SharedModule,
providers: [
MdIconRegistry,
...
IsAuthenticatedGuard,
...
HomeResolver
]
}
}
}
home.module.ts
@NgModule({
imports: [CommonModule, SharedModule],
declarations: [
HomeContainer,
HomeComponent
],
exports: [HomeContainer]
})
export class HomeModule { }
我GE t出現以下錯誤
browser_adapter.js:84 EXCEPTION: Error: Uncaught (in promise): Error: Cannot match any routes: 'home'
任何想法可能是什麼問題?這是路由配置還是模塊問題?感謝
編輯 我忘了模板:
app.component.html
<div>
<router-outlet></router-outlet>
</div>
基本-content.component.html
<md-sidenav-layout fullscreen>
<md-sidenav mode="side" align="start" [opened]="isOpened$ | async" color="warn">
<mainnav-container></mainnav-container>
</md-sidenav>
<page-header-container></page-header-container>
<div class="app-content">
<router-outlet name="content"></router-outlet> // REMOVE NAME
</div>
</md-sidenav-layout>
HomeContainer。層次結構看起來像AppComponent - > BasicContentComponent(在AppComponent的默認中加載) - > HomeContainer(加載在BasicContentComponent的中) - **這是對刪除評論** –
KenavR