【发布时间】:2019-03-20 08:21:07
【问题描述】:
我正在为嵌套的路由器插座苦苦挣扎。我的情况是这样的:
我的 app.components.html 中有一个 <router-outlet>
然后我通过 url 延迟加载我的 desktop.module.ts 模块:/d。
看起来像这样:
const routes: Routes = [
{ path: 'workout', component: WorkoutComponent, outlet: 'desktop'},
{ path: '', component: DesktopComponent, pathMatch: 'full' }
];
@NgModule({
imports: [
CommonModule,
IonicModule,
RouterModule.forChild(routes)
],
declarations: [WorkoutComponent, DesktopComponent],
})
export class DesktopModule {}
现在在我的desktop.component.html 里面我有另一个这样的出口:
<router-outlet name="desktop"></router-outlet>
在桌面组件内部,我想使用“桌面”插座路由到我的WorkoutComponent。所以使用 url:/d/workout 我在 DesktopComponent 中显示我的 WorkoutComponent。
但我似乎无法前往锻炼路线。我试过这个:
[routerLink]="/d/workout, outlet: { "desktop" }"
routerLink="/d/(desktop:workout)"
但两者都不起作用,我找不到任何有效的答案。
【问题讨论】:
-
在
DesktopComponent中显示WorkoutComponent第一个应该是第二个的子级。命名的路由器插座不能与兄弟姐妹一起使用。所以换句话说,你需要创建一个名为 router-outlet 的父组件,然后使用WorkoutComponent作为子组件 -
@BotanMan 我尝试将锻炼路线设置为子路线,但我仍然无法导航到 d/workout 或 d/(desktop:workout) 之类的内容。不过感谢您的帮助!
-
@BotanMan 没关系,我刚刚找到了一个灵魂