我有BookModules和2个组件BookCreate和BookEdit。 使用lazyload模块时如何区分它们。 假设我有2个按钮在主页中创建和编辑。我要单击每个按钮,将导航到bookCreate / bookEdit组件
我想要这样:myweb / store / book-> BookCreateComponent myweb / profile / 12345 / edit-> BookEditComponent 在HomeRoutes中
{
path: 'book',
loadChildren: 'app/run/run.module#BookModule'
}
在BookRoutes中
{
path: '',
component: BookCreateComponent
}
// I don't know how routing to BookEditComponent
答案 0 :(得分:1)
看看我的例子:
use any option 1 or 2
1) {
path: "profile",
loadChildren: "app/profile/profile.module#ProfileModule"
},
2) {
path: "profile",
loadChildren: "./profile/profile.module#ProfileModule"
},
{
path: '',
component: ProfileComponent
}
{
path: ':id',
component: BookCreateComponent
}
{
path: ':id/edit',
component: BookEditComponent
}
<a [routerLink]="['/profile/'+ user_id]">create</a>
<a [routerLink]="['/profile/' + user_id +'/edit']">edit</a>
答案 1 :(得分:0)
如果我对您的理解正确,我会向BookModule添加第二条路线:
{
path: '',
component: BookCreateComponent
},
{
path: 'edit',
component: BookEditComponent
}
然后您可以像这样路由到它:
[routerLink]="book/edit" -> BookEditComponent
[routerLink]="book" -> BookCreateComponent