gilsdav / ngx-translate-router

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

Preloaded routes are not translated #83

Closed Jonnyprof closed 4 years ago

Jonnyprof commented 4 years ago

Hi, I've updated version from 3.0.0 to 3.1.2 and some routes are not translated. After some investigation, I've discovered that preloaded routes with PreloadingStrategy are not translated. When a lazy module with routes is loaded, the routes are translated in https://github.com/gilsdav/ngx-translate-router/blob/bd0ffcf523b6cd49e0e79380288a5399b421fd12/projects/ngx-translate-router/src/lib/localize-router-config-loader.ts#L63

But when a lazy module with routes is preloaded not calls the initChildRoutes method. The entering point when a module is preloaded in the router library is https://github.com/angular/angular/blob/1f0c1f3ff2170d6a333897f5d9a89e3857a4e5f8/packages/router/src/router_preloader.ts#L132

    return this.preloadingStrategy.preload(route, () => {
      const loaded$ = this.loader.load(ngModule.injector, route);
      return loaded$.pipe(mergeMap((config: LoadedRouterConfig) => {
        route._loadedConfig = config;
        return this.processRoutes(config.module, config.routes);
      }));
    });
  }

Removing preloadingStrategy: PreloadAllModules in router configuration works as expected.

Minimal reproduction

https://stackblitz.com/github/jonnyprof/ngx-translate-router-preload

Steps to reproduce: 0- Go to home or login page 1- Click to login -> forgot password. It returns a 404 2- If you reload the page it works fine

If you comment (or remove) preloadingStrategy from src/app/app-routing.module.ts it works as expected.

Explanation:

The routes from PasswordModule haven't been translated and compares 'RESET' with 'reset' in defaultUrlMatcher method. As there is no matcher it returns a 404 route.

Versions: @angular/*: 9.1.12 @gilsdav/ngx-translate-router": 3.1.2

Jonnyprof commented 4 years ago

@gilsdav Do you have any idea? I can help, but I don't know how to fix it...

gilsdav commented 4 years ago

Hello @Jonnyprof, Thank's for your investigation and your stackblitz reproduction. I can see this happened since the very latest release (3.1.2). If you are not using Angular universal you can use the 3.1.1 version (3.1.2 only contains Angular Universal fix). If you accept I will check that and ask you to test a prerelease of the 3.1.3.

gilsdav commented 4 years ago

Can you try this prerelease ? npm i https://github.com/gilsdav/ngx-translate-router/releases/download/3.1.3/gilsdav-ngx-translate-router-3.1.3.tgz

Jonnyprof commented 4 years ago

Sure, thanks! Tomorrow morning I'll tell you something

Jonnyprof commented 4 years ago

It works now, thanks a lot!

gilsdav commented 4 years ago

Fixed in version 3.1.3