router.navigate(['sample', 'route']) is changing url of page but control is not getting inside ngOnInit()

59 Views Asked by At

I recently updated my project from Angular 15 to Angular 17. Since then I have been having this issue.

When this.router.navigate(['sample', 'route']) function is triggered, the URL gets changed but the page is not loaded. I debugged in the browser and saw that the control is not getting inside ngOnInit() function of the component called.

This functionality was working fine in previous version i.e., Angular 15

1

There are 1 best solutions below

0
Jairus Shole On

I ran into the same issue; assuming you are injecting the Router instance using the inject method, please note that there is a difference between Inject(Router) and inject(Router)

import { Inject, inject } from '@angular/core';

You need to use the latter. i.e.

import { inject } from '@angular/core';