Skip to content
Advertisement

Angular Nested Child Routing

I am learning use of multiple router-outlet.

While using navigateBy function of router, i am not able to view my child route and getting error. But if i access it via routerLink in html i get the desired output.

So in below code, navigation to songs is working , but navigation to films is not.

JavaScript

App Component html

JavaScript

Bollywood Component html

JavaScript
JavaScript

StackBitz Link https://stackblitz.com/edit/angular-ivy-1nzkus?file=src/app/bollywood/bollywood.component.html

Advertisement

Answer

In router.navigate, you can pass relativeTo as the second param.

JavaScript

This way navigation will happen relative to the current route. In the constructor you can add the ActivatedRoute dependency.

JavaScript

If you use <button [routerLink]="['songs']"> Songs </button>, the navigation by default happens relative to the current route.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement