4
我試圖讓孩子路由的工作,這是我得到的錯誤:角2 RC5孩子路由問題
EXCEPTION: Error: Uncaught (in promise): Error: Cannot match any routes: 'settings'
這裏是我的app.modules.ts
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { AppComponent } from './app.component';
import { routeComponents, routing, appRoutingProviders } from './app.routes';
@NgModule({
declarations: [
AppComponent,
routeComponents
],
imports: [
BrowserModule,
CommonModule,
FormsModule,
routing
],
providers: [ appRoutingProviders ],
entryComponents: [AppComponent],
bootstrap: [AppComponent]
})
export class AppModule {
}
這裏是我的app.routes.ts
import { Routes, RouterModule } from '@angular/router';
import { DashboardComponent } from './dashboard/';
import { settingsRoutes, settingsComponents } from './settings/';
const appRoutes: Routes = [
{ path: '', redirectTo: 'dashboard', pathMatch: 'full'},
{ path: 'dashboard', component: DashboardComponent },
...settingsRoutes
];
export const appRoutingProviders: any[] = [
];
export const routeComponents: any[] = [
DashboardComponent,
...settingsComponents
];
export const routing = RouterModule.forRoot(appRoutes, {useHash: true});
這裏是我的settings.routes.ts
import { Routes } from '@angular/router';
import { SettingsComponent } from "./settings.component";
import { DashboardSettingsComponent } from "./dashboard-settings/dashboard-settings.component";
export const settingsRoutes: Routes = [
{
path: 'settings',
component: SettingsComponent,
children: [
{ path: 'dashboard-settings', component: DashboardSettingsComponent }
]
}
];
export const travelSettingsComponents = [
SettingsComponent,
DashboardSettingsComponent
];
**如果我刪除從settings.routes.ts文件這一行,沒有錯誤,它可以讓我去設置路線:
{ path: 'dashboard-settings', component: DashboardSettingsComponent }
釷anks。這對我有效,但是當我添加默認的子路徑時,我不得不組件。看起來你也需要從頂層路線中移除'component:SettingsComponent'來解決這個問題。 –