How to get parameter from navigateByUrl?

OPV

I do navigation using:

this.router.navigateByUrl(item.url);

Where item.url has value:

orgtree/1

Route is:

{
        path: "orgtree/:orgstructure",
        component: OrganizationsComponent
      }

Inside component I do:

 ngOnInit() {
    this.route.paramMap.subscribe(params => {
      console.log(params);

    });
}

Why I get empty params?

Also I have tried this:

this.router.navigate(['/orgtree', 1]);

NO EFFECT

I got problem:

Route should be:

{
        path: "orgtree",
        component: OrganizationsComponent
      }
StepUp

You should declare your variables and then use it:

import { ActivatedRoute } from '@angular/router';

constructor(private route: ActivatedRoute) {
  this.route.paramMap.subscribe( params => {
    this.orgstructure = params.get('orgstructure');    
  });
}

UPDATE:

You should declare your parameters like that:

this.router.navigate(['/orgtree'], {queryParams: {orgstructure: 1}});

OR if you want to use navigateByUrl method:

const url = '/probarborrar?id=33';
this.router.navigateByUrl(url);

Please, see work demo at stackblitz.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related