gilsdav / ngx-translate-router

Translate routes using ngx-translate
131 stars 43 forks source link

LocalizeRouter not working on Angular 15.1.1 with SSR (initialNavigation problem) #141

Closed vrady closed 1 year ago

vrady commented 1 year ago

Current Behavior

After upgrading to Angular 15.1.1 from Angular 15.0.4 the application don't bootstrap

The problem with initial navigation. As documentation said we need to use initialNavigation: 'disabled' for RouterModule and use initialNavigation: true for LocalizeRouterModule

@NgModule({
  imports: [
    RouterModule.forRoot(routes, {
      initialNavigation: 'disabled',
    }),
    LocalizeRouterModule.forRoot(routes, {
      parser: {
        provide: LocalizeParser,
        useFactory: (
          translate: TranslateService,
          location: Location,
          settings: LocalizeRouterSettings
        ) =>
          new ManualParserLoader(translate, location, settings, ['en', 'es']),
        deps: [TranslateService, Location, LocalizeRouterSettings],
      },
      alwaysSetPrefix: false,
      defaultLangFunction: () => 'en',
      initialNavigation: true,
    }),
  ],
  exports: [RouterModule, LocalizeRouterModule],
})
export class AppRoutingModule {}

But with this config application not started as well. There is no errors in console too

image

Once you comment initialNavigation: true for LocalizeRouterModule and change initialNavigation for RouterModule to enabledBlocking the application bootstrapped:

image

I guess the problem with this line of code https://github.com/gilsdav/ngx-translate-router/blob/e0d92ba73098f1c3d7b0d3ec2309c9f25ce5454f/projects/ngx-translate-router/src/lib/localize-router.service.ts#L64 Because if you call router.initialNavigation() for example in APP_INITIALIZER after LocalizeRouterService initialized with hook initialized the application will be bootstrapped. But this calling cause another issue for med with RouterStore from NgRX.

Maybe there are some breaking changes in Angular 15.1 for the library with Router. Maybe now we need to call router.initialNavigation() in another place of LocalizeRouterService.

@gilsdav can you check this problem? Thanks :)

Raphy commented 1 year ago

We are facing the same issue and it's blocking our migration !

karimzg commented 1 year ago

Hi,

Same issue after migrating to Angular 15.1.1.

I add this clarification:

#Once you comment initialNavigation: true for LocalizeRouterModule and change initialNavigation for RouterModule to enabledBlocking the application bootstrapped:

After commenting out the "InitialNavigation: true" for the LocalizeRouterModule:

Thanks!

hudzenko commented 1 year ago

We have the same issue.

gilsdav commented 1 year ago

Thank's all for your investigation. As @karimzg says, you can remove all notions of "InitialNavigation" to make it works for now. I need to investigate because Angular did alot of changes into its Router.

karimzg commented 1 year ago

@gilsdav Do you think you could find a solution?

hudzenko commented 1 year ago

Hi, @gilsdav! Thank you for the amazing library!

Are you able to find some time for this issue?

We are using SSR and do need InitialNavigation. The library is blocking us now from upgrading to the latest angular updates.

matte0080 commented 1 year ago

I have this issues too, any solutions?

"@angular": "^15.2.1"
"@gilsdav/ngx-translate-router": "^6.0.0",
"@gilsdav/ngx-translate-router-http-loader": "^2.0.0",
vrady commented 1 year ago

Hi @gilsdav.

I've created PR which should resolve this issue https://github.com/gilsdav/ngx-translate-router/pull/143.

Please check it out. I tried for myself and this fix works for my project

gilsdav commented 1 year ago

@gilsdav/ngx-translate-router@6.1.0 published