-1

I need pass a param from one route to other but it should not visible to user. I need it in Angular 6.

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
Madhavi
  • 474
  • 2
  • 7
  • 20

2 Answers2

0

If you don't want the URL to change you can use skipLocationChange strategy.

https://angular.io/api/router/NavigationExtras

rootkill
  • 599
  • 5
  • 10
0

You could use matrix params.

Then using the Angular location, and router services, to read and then overwrite the URL history.

It isn't elegant but works..and achieves what you asked.

Example for the check and re-write of location history:

this.router.events.pipe(filter(event => event instanceof NavigationEnd))
.subscribe((event: NavigationEnd) => {
  const matrixParams = this.location.path().split(';');

  ... do something with the matrixParam

  if(matrixParams.length > 1) {
    this.location.replaceState(matrixParams[0])
  }

}));

Other ideas (as mentioned):

  • Use a service to pass the data around, check for it in OnInit
  • As mentioned, pass it between components using @Input()
Jmsdb
  • 515
  • 3
  • 9