Angular 4-使用HashLocationStrategy时如何读取查询字符串参数

时间:2018-11-27 17:53:35

标签: angular hash-location-strategy

使用HashLocationStrategy时,查询字符串参数将被忽略/删除。

例如,如果我有一个http://localhost:8080/?id=1这样的网址

然后在组件中的ngOnInit()

我试图按如下方式读取id的值:

this.activatedRoute.snapshot.queryParamMap.get(“ id”);

如果我从路由器配置中删除useHash,这将起作用。

如果将useHash设置为true,即,如果我使用HashLocationStrategy,它将剥离并且ActivateRoute无法看到id参数。

请告知。

0 个答案:

没有答案