简体   繁体   中英

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. One of the is the is the 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.

@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.

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;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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