防止镀铬剥离URL参数



我正在使用Angular 6应用程序,我想阅读位于URL中的项目的ID。例如www.mywebsite.com/3,我试图检索3。示例URL)我依靠在后端检索该项目。这个问题有解决方法吗? 谢谢。

在TS

export class YourXPTOComponent implements OnInit {
  id: string;
  constructor(private route: ActivatedRoute) { }
  ngOnInit() {
    this.id = this.route.snapshot.paramMap.get('id');
  }
}

在您的路线中

  {
    path: 'yourPath/:id',
    component: YourXPTOComponent,
  },

我能够通过向URL添加额外的#来解决此问题。因此,如果我们有www.mysite.com/#/3,3将留在Chrome的地址栏中。

最新更新