我在angular2应用程序中有一个已定义的路由并收到此类错误:
无法匹配任何路线:''
export const routes: Routes = [{
path: '',
component: MainComponent,
children: [{
path: 'callCenter',
component: CallCenterComponent,
resolve: {
countries: CountriesResolver
},
}, {
path: 'vehicle',
component: VehicleComponent,
resolve: {
vehicleCategories: VehicleCategoryResolver,
vehicleOptions: VehicleOptionResolver
},
}, {
path: 'territory',
component: TerritoryComponent,
resolve: {
territoryOptions: TerritoryOptionResolver
}
},{
path: 'token',
component: TokenGenerationComponent
}, {
path: 'rider',
component: RiderComponent
}, {
path: 'dispatch',
component: DispatchSchemaComponent,
resolve: {
dispatchOrders: DispatchOrderResolver,
dispatchModes: DispatchModeResolver
}
}]
}, {
path: 'login',
component: LoginComponent
}];

这是我的路线配置的代码。我使它与示例中的相同,但它不起作用,redirectTo属性也没有帮助。默认空路由未加载。有谁可以帮助我?
答案 0 :(得分:1)
我认为angular期望MainComponent子路由具有路径''。
export const routes: Routes = [{
path: '',
component: MainComponent,
children: [{
path: '',
component: SomeComponent
},
{
path: 'callCenter',
component: CallCenterComponent,
resolve: {
countries: CountriesResolver
},
}, {
path: 'vehicle',
component: VehicleComponent,
resolve: {
vehicleCategories: VehicleCategoryResolver,
vehicleOptions: VehicleOptionResolver
},
}, {
path: 'territory',
component: TerritoryComponent,
resolve: {
territoryOptions: TerritoryOptionResolver
}
},{
path: 'token',
component: TokenGenerationComponent
}, {
path: 'rider',
component: RiderComponent
}, {
path: 'dispatch',
component: DispatchSchemaComponent,
resolve: {
dispatchOrders: DispatchOrderResolver,
dispatchModes: DispatchModeResolver
}
}]
}, {
path: 'login',
component: LoginComponent
}];
修改强> 有一些重定向
export const routes: Routes = [
{
path: '',
component: MainComponent,
children: [
{
path: '',
redirectTo: 'callCenter'
},
{
path: 'callCenter',
component: CallCenterComponent,
resolve: {
countries: CountriesResolver
},
}, {
path: 'vehicle',
component: VehicleComponent,
resolve: {
vehicleCategories: VehicleCategoryResolver,
vehicleOptions: VehicleOptionResolver
},
}
...
将MainComponent移动到子路径也应该起作用
export const routes: Routes = [
{
path: '',
children: [
{
path: '',
component: MainComponent
},
{
path: 'callCenter',
component: CallCenterComponent,
resolve: {
countries: CountriesResolver
},
}, {
path: 'vehicle',
component: VehicleComponent,
resolve: {
vehicleCategories: VehicleCategoryResolver,
vehicleOptions: VehicleOptionResolver
},
}
...