繁体   English   中英

有没有办法判断Angular 8中的RouterModule useHash是否设置为true?

[英]Is there a way to tell if the RouterModule useHash in Angular 8 is set to true?

我正在为我的工作开发一个库,它允许其他开发团队使用我们的一些 Angular 组件并在其中传递自己的配置。 其中之一是 RouterModule。

我在我们的库中找到了一些代码,我需要确定它们是否在模块的配置中启用useHash: true参数。

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

我真正需要做的就是查看它是否已设置为 true 或 false 或 null,但我一直在梳理文档并搜索 Google,但我被难住了。

我尝试了一些简单的方法,但这当然行不通。

constructor(private route: ActivatedRoute, private router: Router, private module: RouterModule) {
   console.log(router.useHash)
}

有谁知道这是可能的吗?

答案来晚了,但可能对某人仍然有用。

constructor(private platformLocation: PlatformLocation) {
}

useHash() {
  return this.platformLocation.hash?.indexOf('#') > -1;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM