如何路由到另一个模块子组件?
我有核心模块,我持有NavBar组件。从NavBar组件中,单击其中一个链接,我应该从Core将用户重定向到通知组件。但是,我需要将url定义为/profesor/通知。
NavBar组件:
<li><a routerLink="/profesor/notifications"><i class="fa fa-bars"></i> Notifications </a></li>
我在NavBar路由模块中没有任何定义的路由。
在应用程序中.模块
{ path: 'profesor', component: ProfesorHomeComponent },
在专业的.模块中
const routes: Routes = [
{ path: '', component: ProfesorHomeComponent },
{ path: 'notifications', component: NotificationsComponent },
];
我做错了什么?
StackBlitz:现在有Stackblitz了,如果你能查出来的话。但请只将/profesor添加到链接中,然后尝试导航到职业/通知。
https://stackblitz.com/edit/angular-ivy-vdytbz?file=src%2Fapp%2Fprofesor%2Fprofesor.module.ts
发布于 2022-02-20 07:29:46
通知不是教授模块的子类。若要解决此问题,请将通知移动到子路由。
const routes: Routes = [
{ path: '', component: ProfesorHomeComponent ,
children : [
{ path: 'notifications', component: NotificationsComponent }]},
];
在ProfesorHomeComponent HTML模板中包括路由器出口以呈现子组件。
<router-outlet></router-outlet>
或者,如果模块不是懒散负载,则可以直接调用通知。
<li><a routerLink="/notifications"><i class="fa fa-bars"></i> Notifications </a></li>
发布于 2022-02-20 08:48:47
我是怎么做到的。导航条看起来是这样的:
<a [routerLink]="['/main', { outlets: { c: ['dashboard'] } }]">
Dashboard </a>
<a [routerLink]="['/main', { outlets: { c: ['membership'] } }]">
Memberships </a>
<a [routerLink]="['/main', { outlets: { c: ['client'] } }]">
Clients </a>
路由模块是:
const appRoutes: Routes = [
{ path: 'main', component: MainComponent, children: [
{path:'dashboard', component: DashboardComponent, outlet: 'c'},
{path:'membership', component: MembershipComponent, outlet: 'c'},
{ path: 'client', component: ClientComponent, outlet: 'c' },
]},
];
然后在主要组件内部:
<router-outlet name="c"></router-outlet>
如果您需要更详细的说明,请告诉我。
https://stackoverflow.com/questions/71195712
复制