angularrouterangular-routerangular-activatedroute

How pass parameters from urlA to urlB without show them in the url


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 proble 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 I can take parameters. Anyone can help me?


Solution

  • Use this:

    let data = {name: 'erika'}
    this.router.navigateByUrl([URLB], data);
    

    and this:

    this.activatedRoute.data
      .subscribe(
        (data: Data) => {
          this.name = data['name'];
        }
      );