Closed DavidCMeier closed 3 years ago
Ok, I know that is not a perfect solution but...
@NgModule({
imports: [
LocalizeRouterModule.forRoot(routes, {
parser: {
provide: LocalizeParser,
useFactory: localizeLoaderFactory,
deps: [TranslateService, Location, LocalizeRouterSettings, TransferState, HttpClient],
},
}),
RouterModule.forRoot(routes),
],
exports: [RouterModule],
})
export class AppRoutingModule {
constructor(@Inject(ROUTER_CONFIGURATION) private config: ExtraOptions, transferState: TransferState) {
const ROUTES_KEY = makeStateKey('ROUTES')
if (transferState.hasKey(ROUTES_KEY)) {
config.initialNavigation = 'enabled'
}
console.log('AppRoutingModule', config)
}
}
With that code into the class of the Module, depends if we have the data into transferState or not we can modify the config.
@DavidCMeier , i have the same problem, can you please explain me how your solution works so i can try to use it?
hi @hymenoby of course.
When the constructor initialize we inject the ROUTER_CONFIGURATION token and if i have the KEY into the transferState is because we are on server (because we set the key on app.server.module.ts).
So if this is right, we modify the initiaNavigation to 'enable'.
Of course, probably yo can do that:
export class AppRoutingModule {
constructor(@Inject(ROUTER_CONFIGURATION) private config: ExtraOptions,
@Inject(PLATFORM_ID) private platformId: Object) {
const ROUTES_KEY = makeStateKey('ROUTES')
if(isPlatformServer(this.platformId) config.initialNavigation = 'enabled'
}
}
Because this repo es abbandoned i close the Issue. If anybody need continue using I recomend looking for a fork like https://github.com/gilsdav/localize-router
I'm submitting a ... (check one with "x")
Description
When we use InitialNavigation: 'enabled' our routings (without using universal) doesn't work. Just work with Universal.
π¬ Minimal Reproduction (if applicable)
app-routing.module.ts
π Your Environment
Angular Version:
Localize Router Version:
Anything else relevant?