Search code examples
angularangular-router

Cannot read property 'outlets' of null in Angular 6


I'm trying to use routerLink and router-outlet but I'm getting Cannot read property 'outlets' of null issue in my Angular 6 project.

I was able to recreate the issue in this simple example Angular 6 project here https://stackblitz.com/edit/angular-dk8i8y

The error comes when a route link is clicked, although the value is hardcoded.

<a [routerLink]="['/manage', 'plugins' ]" > Plugins </a>

Can you please advise?


Solution

  • I'm not entirely sure if this can be done differently, but with a not named outlet this works.

    Also when you change routes the components are not recreated again, so you need to subscribe to the route params to get notified when the route changes. In these cases it is often a good idea to use the async pipe, since it takes care of unsubscribing when the component is destroyed. I have updated the Stackblitz below:

    https://stackblitz.com/edit/angular-qppimo