0

Here is my code and I am trying to navigate to '/employee-profile/empId' while pressing browser back button, but this code doesn't work properly

I have tried using PlatformLocation here.

 this.location.onPopState(() => {
    console.log('pressed back!');
    this.router.navigate(['/employee-profile/empId']);
  });
anand raj
  • 1
  • 1
  • Is `empId` a variable holding some value? Could you also post a snippet of what your configured routes look like? Also, being more descriptive about what is happening when you say "doesn't work properly" will help you get an answer faster. :) – Ravi Mashru Jul 26 '19 at 10:50
  • Yes, I'm passing some value to the empId. While clicking browser back button, I need to navigate to the same url with previous empId value which I have stored in local, instead of going to the previous url. But now, it is going to previous url. I have tried using the methods mentioned on https://stackoverflow.com/questions/40381814/how-do-i-detect-user-navigating-back-in-angular2. – anand raj Jul 26 '19 at 11:19

1 Answers1

0

The problem might be the way you are specifying empId. Like you said, it is a route parameter, but the way you've specified it is as a string literal.

Changing the method call to this.router.navigate(['/employee-profile', empId]); will navigate with empId as a route parameter.

For more details on how this works, you can check out the Angular official documentation about the link parameters array.

Ravi Mashru
  • 497
  • 3
  • 10