0

I want to define web site language on url. Such as "mysite.com/en/blabla". But I have different languages for each customer. And If customer does not support english, angular should return 404 and I try this:

const languages:Routes = Object.getOwnPropertyNames(environment.trader.langList).map(path => {
  return {
    path, component: OutComponent,
    children: [
      { path: 'place-bet', loadChildren: '../../desktop/placebet/placebet.module#PlacebetModule' },
      { path: 'games', loadChildren: '../../desktop/games/games.module#GamesModule' },
      { path: 'dashboard', loadChildren: '../../desktop/dashboard/dashboard.module#DashboardModule' }]
  };
})
debugger;

const OutRoutes: Routes = [
  ...languages
];

export const OutRouter = RouterModule.forChild(OutRoutes);

I get languages from environment and generate routes for each language. This works for run time but when I compile, it gives an error : "ERROR in Cannot read property 'loadChildren' of undefined". It can't compile mapped routes on compile time. How can I resolve it?

Kamuran Sönecek
  • 3,293
  • 2
  • 30
  • 57

1 Answers1

1

Found this : https://medium.com/@gustavopollitzer/thank-you-a-lot-a357e95e43b8

Basically, it says only static assignments are allowed and function calls arent supported in @NgModule declaration. Routing is done via a NgModule, yeah?

If you wanted custom URLs for th list of supported languages in your case, why dont you use the custom path

like path: ':lang/place-bet'

How to pass a parameter to routerLink that is somewhere inside the URL?

Hope this helps :)

D.B.K
  • 410
  • 2
  • 15