如何从navigateByUrl获取参数?

OPV*_*OPV 2 angular angular8

我使用以下方式进行导航:

this.router.navigateByUrl(item.url);
Run Code Online (Sandbox Code Playgroud)

item.url有价值的地方:

orgtree/1
Run Code Online (Sandbox Code Playgroud)

路线是:

{
        path: "orgtree/:orgstructure",
        component: OrganizationsComponent
      }
Run Code Online (Sandbox Code Playgroud)

我做的内部组件:

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

    });
}
Run Code Online (Sandbox Code Playgroud)

为什么我得到空参数?

我也尝试过这个:

this.router.navigate(['/orgtree', 1]);
Run Code Online (Sandbox Code Playgroud)

没有效果

我遇到问题:

路线应该是:

{
        path: "orgtree",
        component: OrganizationsComponent
      }
Run Code Online (Sandbox Code Playgroud)

Ste*_*pUp 6

您应该声明变量然后使用它:

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

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

更新:

你应该这样声明你的参数:

this.router.navigate(['/orgtree'], {queryParams: {orgstructure: 1}});
Run Code Online (Sandbox Code Playgroud)

或者如果你想使用navigateByUrl方法:

const url = '/probarborrar?id=33';
this.router.navigateByUrl(url);
Run Code Online (Sandbox Code Playgroud)

请参阅 stackblitz 的工作演示。