Skip to content
This repository has been archived by the owner on Nov 21, 2019. It is now read-only.

access route based on language set in url #63

Open
Scipionh opened this issue Oct 15, 2017 · 2 comments
Open

access route based on language set in url #63

Scipionh opened this issue Oct 15, 2017 · 2 comments

Comments

@Scipionh
Copy link

Scipionh commented Oct 15, 2017

I have followed your guide which is great.
However, I have something not working. Basically, my router looks like this:

const routes: Routes = [
  {
      path: '', children: [
         { 
            path: 'dummy', component: DummyComponent
         }
      ],
      data: {
          i18n: {
              isRoot: true
          }
      }
  },
    {
        path: 'change-language/:languageCode',
        component: ChangeLanguageComponent
    },
    {
        path: '**',
        redirectTo: '',
        pathMatch: 'full'
    }
];


@NgModule({
  imports: [RouterModule.forRoot(routes),
      I18NRouterModule.forRoot(routes, [
          {
              provide: I18NRouterLoader,
              useFactory: (i18nRouterFactory),
              deps: [Http, RAW_ROUTES]
            }
      ])
],
  exports: [RouterModule, I18NRouterModule ]
})
export class AppRoutingModule { }

and in my routes.json:

{
  "en": {
    "ROOT.DUMMY":"dummyen"
  },
  "fr": {
    "ROOT.DUMMY":"dummyfr"
  }
}

app.component.ts

export class AppComponent implements OnInit {
    constructor(private readonly i18nRouter: I18NRouterService) {
        i18nRouter.init()

    }

    ngOnInit() {
      this.i18nRouter.changeLanguage('en');
    }
}

If I try to access en/dummyen it works fine. However if I try to access, directly by modifying the url fr/dummyfr it doesn't work. Which is normal since I would need to do a this.i18nRouter.changeLanguage('fr');

I am just not sure how to do this. Is this something I should be able to do ?

@fulls1z3 fulls1z3 changed the title Access route based on language set in url access route based on language set in url Jan 7, 2018
@fulls1z3 fulls1z3 added this to the v5.0.1 milestone Jan 7, 2018
@mappedinn
Copy link

+1

@mappedinn
Copy link

Any plan to upgrade to angular 6?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants