Angular 12 Language Prefix support

Skip to first unread message

alan morano

Oct 5, 2022, 1:50:21 AM10/5/22
to Angular and AngularJS discussion
Hi everyone, 

I am writing an i18n feature for my app, but for each supported language I want to add a prefix to my url e.g.: (for english) (for french) (for italian)
and so on.

I am using ngx-translate and it is fully working in my app, and I have already tried using a provider for APP_BASE_HREF. ex:
      provide: APP_BASE_HREF,
      useFactory: () => {
        const storedLang =  localStorage.getItem('cr-preferred-lang');
        if (environment.supportedLanguages.includes(storedLang)) {
          return storedLang === 'en' ? '/' : `/${storedLang}`;
        } else {
          localStorage.setItem('cr-preferred-lang', 'en');
          return '/';

But whenever I deploy this and try to access a page with the prefix on a new tab it gets returned as error 500.

I have been stuck on this for weeks now, and I am not sure how to handle it.

Any help would be great. Thanks :) 

Gaurav Kumar

Nov 26, 2022, 3:38:26 AM11/26/22
to Angular and AngularJS discussion
Reply all
Reply to author
0 new messages