假设我有以下设置:
employee -------+ employee.module.ts
| employee.routing.ts
+ employee.component.ts
|
sales ----------+ sales.module.ts
| sales.routing.ts
+ sales.component.ts
app.module.ts
app.routing.ts
app.component.ts
我希望我的路线看起来像
employee/14/sales
所以我继续定义这些路由声明:
app.routing.ts
...
import { AppComponent } from './app.component';
const appRoutes: Routes = [
{ path: '', component: AppComponent }
];
export const appRoutingProviders: any[] = [];
export const routing = RouterModule.forRoot(appRoutes, { useHash: true });
员工路由.ts
...
import { EmployeeComponent } from './employee.component';
export const employeeRoutes: Routes = [
{ path: 'employee/:id', component: EmployeeComponent }
];
export const employeeRouting = RouterModule.forChild(employeeRoutes);
sales.routing.ts
...
import { SalesComponent } from './sales.component';
export const salesRoutes: Routes = [
{ path: 'sales', component: SalesComponent }
];
export const salesRouting = RouterModule.forChild(salesRoutes);
而我的模块采用这种形式:
app.module.ts
import { EmployeeModule } from './employee/employee.module';
import { AppComponent } from './app.component';
import {
routing,
appRoutingProviders
} from './app.routing';
@NgModule({
imports: [
...
EmployeeModule,
routing
],
declarations: [
AppComponent
],
bootstrap: [
AppComponent
],
providers: [
appRoutingProviders
]
})
员工模块.ts
import { SalesModule } from '../sales/sales.module';
import { EmployeeComponent } from './employee.component';
import { employeeRouting } from './employee.routing';
@NgModule({
imports: [
SalesModule,
employeeRouting
],
declarations: [
EmployeeComponent
]
})
sales.module.ts
import { SalesComponent } from './sales.component';
import { salesRouting } from './sales.routing';
@NgModule({
imports: [
salesRouting
],
declarations: [
SalesComponent
]
})
export class SalesModule {}
我现在可以搬到
employee/14
但如果我尝试导航到
employee/14/sales
我受到了欢迎
错误:无法匹配任何路线:'employee/14/sales'
但是,我可以输入
sales
这在它不应该工作的情况下工作,所以不知何故,所有路线都直接连接到/
而不是建立在彼此之上。
我错过了什么?
可以在此处找到演示该问题的编辑plnkr 。