无法在Angular的Hashlocation策略中获取查询参数

问题描述

我正在Angular中使用哈希定位策略

routing.module.ts

@NgModule({ 
imports: [
   RouterModule.forRoot(routes,{ useHash: true })
 ],exports: [
    RouterModule
  ]
})

app.module.ts

@NgModule({
    providers: [{ provide: LocationStrategy,useClass: HashLocationStrategy }]
})

我正在使用此URL从其他一些应用程序路由到我的角度应用程序

HTTP://localhost:4200?param_x=xyz&param_y=abc

我想在我的应用程序中获取这些参数的值,该怎么办?

我尝试使用激活的路由快照以及订阅,都给了我空值。

解决方法

请打开带有片段参数的客户端。

片段参数是#后面的参数-也称为客户端参数,因为它们没有发送到服务器。

HTTP://localhost:4200?#hash_param_x=xyz&hash_param_y=abc

然后通过以下方式访问它们:

this.activatedRoute.snapshot.queryParams

HashLocationStrategy 获取哈希(片段/客户端)参数,并将其插入查询参数中。由于没有任何参数,因此看不到任何参数。