Change the useHash option in RouterModule in runtime

Viewed 116

I need to load my router module option useHash of Angular application with true and sometime with false. its depends on some server state that I'v getting to the window (global) object.

I've tried to load one of 2 components with ngDoBootstrap (like here this example), and then load for each component, module with router module. the first one, loads with useHash = true, the second one with false.

this is not working with AOT. can I change the useHash option in runtime?

1 Answers

I found an answer for this scenario.

create 2 modules that with different entry component.

add if statement for main.ts

if (window.firstModuleToLoad) {
  platformBrowserDynamic().bootstrapModule(FirstModule)
    .catch(err => console.error(err));
} else {
  platformBrowserDynamic().bootstrapModule(SecondModule)
    .catch(err => console.error(err));
}
Related