My Angular application has three items on its main navigation bar, “One”, “Two”, and “Three”. When I choose “Two”, the loaded component has four tabs, say “Ay”, “Bee”, “Cee”, and “Dee” that route to child routes of the route for “Two”. Under the tabs is a nested router-outlet
where the child route goes. When I click Two, I want the first tab to be the “active” one and display the component for Two Ay in the router-outlet
unless the currently activated route is another child is another child of Two. In that case, I want the view to remain as is. In other words, I want the “Two” item to take the user to Two Ay only if the user is currently on One or Three, and do nothing otherwise.
The routes:
export const routeConfig: Routes = [
{ path: '', pathMatch: 'full', component: OneComponent },
{
path: 'two',
component: TwoComponent,
children: [
{ path: 'ay', component: TwoAyComponent },
{ path: 'bee', component: TwoBeeComponent },
{ path: 'cee', component: TwoCeeComponent },
{ path: 'dee', component: TwoDeeComponent },
],
},
{ path: 'three', pathMatch: 'full', component: ThreeComponent },
{ path: '**', component: NotFoundComponent },
];
The three navigation bar items route to ‘/’, ‘/two/ay‘, and ‘/three’, respectively.
Inside two.component.html I have
<nav ngbNav #nav="ngbNav" class="nav-tabs">
<a ngbNavLink class="nav-link nav-item" [routerLink]="['/two/ay']" [routerLinkActive]="'active'">
Ay
</a>
<a ngbNavLink class="nav-link nav-item" [routerLink]="['/two/bee']" [routerLinkActive]="'active'">
Bee
</a>
<a ngbNavLink class="nav-link nav-item" [routerLink]="['/two/cee']" [routerLinkActive]="'active'">
Cee
</a>
<a ngbNavLink class="nav-link nav-item" [routerLink]="['/two/dee']" [routerLinkActive]="'active'">
Dee
</a>
</nav>
<div class="p-3 border-start border-end border-bottom">
<router-outlet></router-outlet>
</div>
Is there a way to alter this to make the route for “Two” conditional on whether or not one of its children is the currently activated route?