Angular 4 Router: How to not display parameters in the url bar?

Viewed 29747

When I use:

  constructor(router: Router) {
    router.navigate(['page2', 123456789]);
  }

I see example.com/page2/123456789 in the address bar. Is it possible to hide it? I don't want someone to be able to enter example.com/page2 so that he/she navigates to this special page. It should only work internally with the command router.navigate(['xy', 'parameter']);

4 Answers

You can skip the full url display by setting skipLocationChange member true on the router:

this.router.navigate(['/view'], { skipLocationChange: true });

Docs

use the skipLocationChange property could be used to protect a user from seeing URL change.

this.router.navigate(['/url'], { queryParams:  youParam , skipLocationChange: true}); 

You can't hide the parameter in the url. But you can use SessionStoreage for alternative. You can create parameter in SessionStorage and can read in every part of your project until when you close the browser or if you kill the parameter value from SessionStorage.

Related