2

I need to pass parameters from URLA o urlB whithout and the urlB must be show ( so I can't use skiplocation=true).

in my ts I do ( in URLA) :

this.router.navigate([URLB], {
                queryParams:
                {
                    name: "erika"

                }
            });

and when I take the parameter I do:

 this.activatedRoute.queryParams.subscribe(params => {
      this.name = params['name'];

    });

The problem is that it shows me url in this way URLB?name=erika and I don't want to do this, but i want the it show me URLB and pass me hidden parameter. Anyone can help me?

poopp
  • 1,297
  • 2
  • 13
  • 23
  • Can you explain a bit more. it's not clear what you want. I suggest you not using query string or path variable because query string and path variable paramter are visible. The only way that i know to have invisible parameter is to use the payload like in the HTTP POST verb. – Stoic Lion May 27 '20 at 09:24
  • its not possible. what you can do is keep to url to URL A and still navigate – Aakash Garg May 27 '20 at 09:24
  • 1
    Does this answer your question? [Pass invisible or hidden parameters using routerLink Angular](https://stackoverflow.com/questions/46905336/pass-invisible-or-hidden-parameters-using-routerlink-angular) – Aakash Garg May 27 '20 at 09:32

1 Answers1

1

You can use the state in NavigationExtras:

Set data:

this.router.navigate(['yoururl'], { state: yourObject });

Get data:

this.router.getCurrentNavigation().extras.state

https://angular.io/api/router/Router#navigate

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

If you want to use a service, read this: Sharing Data between Components

Marc
  • 1,836
  • 1
  • 10
  • 14