I have a component that uses router to navigate to another component with a boolean variable like this
this.router.navigate(['/consume/course/' + this.id, {state: { isFirst }} ], { replaceUrl: true });
in the other component I am trying to get this variable from the router like this
const isFirst = this.router.getCurrentNavigation().extras.state.isFirst;
but I get this error:
Cannot read property 'extras' of null
Why do I have null for the current navigation?
Also, this is my routing module for the 2nd component
const routes: Routes = [
{
path: 'course/:id',
component: CourseComponent,
canActivate: [RedirectGuard],
data: { menuType: 'test' },
},
];