简体   繁体   English

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

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

I'm working on a library for my job that allows other development teams to use some of our Angular components and pass in there own configurations.我正在为我的工作开发一个库,它允许其他开发团队使用我们的一些 Angular 组件并在其中传递自己的配置。 One of the is the is the RouterModule.其中之一是 RouterModule。

I've found some code in our library where I need to determine if they have enabled he useHash: true parameter in the configuration for the Module.我在我们的库中找到了一些代码,我需要确定它们是否在模块的配置中启用useHash: true参数。

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

All I need to do really is see if it's been set to true or is false or null but I've been combing through the docs and searching Google and I'm stumped.我真正需要做的就是查看它是否已设置为 true 或 false 或 null,但我一直在梳理文档并搜索 Google,但我被难住了。

I tried something simple but of course this does not work.我尝试了一些简单的方法,但这当然行不通。

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

Does anyone know of this is possible?有谁知道这是可能的吗?

The answer comes late but may still be useful to someone.答案来晚了,但可能对某人仍然有用。

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