gilsdav / ngx-translate-router

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

Lazy loading modules incorrect path #149

Closed alexei-petru closed 12 months ago

alexei-petru commented 1 year ago

Issue with lazy loading a module

It looks like a major issue, I am using it wrong or ? Can someone help and give a good solution?

this is fine

this is NOT fine

parent

childrens

alexei-petru commented 1 year ago

I have done a simple temporary workaround, don't really have time for this rn, but I think it's an issue with the library, not sure tho. btw. #142 issue might be similar

I am changing only the lang and not translating the full URL so i don't know if I really need this library tbh.

 public setLang(langObj: LanguageApp) {
    this.languageApp.next(langObj);
    this.translate.use(langObj.value);
    this.changeRoute(langObj.value);
  }

  private changeRoute(lang: LanguageAppValues) {
    // use because of ngx-translate-route lazy modules bug
    const currentUrl = this.router.url;
    const urlParts = currentUrl.split('/');
    if (LANGUAGES_ALL_VAL_ARR.includes(urlParts[1])) {
      urlParts[1] = lang;
      const newUrl = urlParts.join('/');
      console.log(newUrl);
      this.router.navigateByUrl(newUrl);
    }
  }
jemys89 commented 1 year ago
 private changeRoute(lang: LanguageAppValues) {
    // use because of ngx-translate-route lazy modules bug
    const currentUrl = this.router.url;
    const urlParts = currentUrl.split('/');
    if (LANGUAGES_ALL_VAL_ARR.includes(urlParts[1])) {
      urlParts[1] = lang;
      const newUrl = urlParts.join('/');
      console.log(newUrl);
      this.router.navigateByUrl(newUrl);
    }
  }

I don't understand... Why use this library if ngx-translate already solves your use case?

alexei-petru commented 1 year ago

@jemys89 I was thinking maybe I would use other functionality from it later. But I will make manually for the moment. Still, I think there is a bug with lazy loaded modules.

jemys89 commented 1 year ago

@jemys89 I was thinking maybe I would use other functionality from it later. But I will make manually for the moment. Still, I think there is a bug with lazy loaded modules.

Yes, there is a critical bug, after updating to Angular 16, in the (lazy modules) the path is concatenated twice.

jemys89 commented 1 year ago

Since he/she does not respond and I urgently need the fix, I have created this provisional fork, until he/she accepts the PR I have made.

https://www.npmjs.com/package/@jemys89/ngx-translate-router

alexei-petru commented 1 year ago

Since he/she does not respond and I urgently need the fix, I have created this provisional fork, until he/she accepts the PR I have made.

https://www.npmjs.com/package/@jemys89/ngx-translate-router

Good job, thank you.

alexei-petru commented 1 year ago

I better leave it open until the pr will be accepted.

gilsdav commented 12 months ago

Can you check it's correctly fixed on version 7.0.0 ?

alexei-petru commented 12 months ago

Can you check it's correctly fixed on version 7.0.0 ?

@gilsdav Everything good, thank you and everyone involved for fixing it.