Angular 同一路由上的路由器参数

Angular Router param on the same route

路线

{path:'dashboard',component: DashboardComponent },
{path:'dashboard/:id',component: DashboardComponent },

路由器链接

    <li><a [routerLink]="['/dashboard', 'kRX4eLiwmEau8X2SdoKScA==']">Appliances</a></li>
    <li><a [routerLink]="['/dashboard', 'FQtZRfDqtkGrn2II8HobZw==']">Tools and Gadgets</a></li>
    <li><a [routerLink]="['/dashboard', 'EMz9RMY4RESyKtvFVAJTVQ==']">Table Linen</a></li>
    <li><a [routerLink]="['/dashboard', 'BamlddxbUk2lx3uhaT4Hbg==']">Bakeware</a></li>
    <li><a [routerLink]="['/dashboard', 'VZxPmhcsxEmOGLTvp5Mvxw==']">Serveware</a></li>
    <li><a [routerLink]="['/dashboard', 'QEkCu3nN5UWYBHmCOuvGUA==']">Serveware</a></li>
    <li><a [routerLink]="['/dashboard', 'DKHH6dljMkWazcakJSxC1g==']">Decor</a></li>

代码

ngOnInit() {
   this.sub = this.route.params.subscribe(params => {
      this.id = params['id']; // (+) converts string 'id' to a number
      // In a real app: dispatch action to load the details here.
   });
   console.log( this.id )
   let postdata = {
     id :this.id
   }

  axios({
    method: 'post',
    data: this.serializeObj(postdata),
    url: this.initialapi+'/Product/GetProducts',
    headers: {
        'Content-Type':'application/x-www-form-urlencoded',
    }
    }).then(response => {
        console.log(_.uniqBy(response.data,'id'))
        this.productlist = _.uniqBy(response.data,'id')

    })
    .catch(function (error) {
        console.log(error);

    });
}

我想做的是,当我点击任何路由器时 link 然后参数将存储在一个变量中并转到我的 post 命中,虽然当我刷新时它正在工作我的页面因为我正在使用 ngOnInit().

上的 http 命中

当我单击 link 时,我如何才能完成这项工作,它会为我提供数据,有什么方法可以让我在每次单击路线并在同一路线上获得数据时获得这些数据

这就是它的完成方式,现在正在运行

 this.route.paramMap.subscribe(params => {
  console.log(params.get('id'));
  this.id = params.get('id');
// data hit
      let postdata = {
        id :this.id
      }
     axios({
        method: 'post',
        data: this.serializeObj(postdata),
        url: this.initialapi+'/Product/GetProducts',
        headers: {
            'Content-Type':'application/x-www-form-urlencoded',
        }
        }).then(response => {
            console.log(_.uniqBy(response.data,'id'))
            this.productlist = _.uniqBy(response.data,'id')

        })
        .catch(function (error) {
            console.log(error);
        });
    });