Tom
Tom

Reputation: 795

Loading router's paths from external files

I' trying to build an app that can be used from different country in different language. The idea is to have paths that uses good keywords for SEO in each country.

The json file loaded depends on the path url: /uk, /fr, /es loads uk.js, fr.js or es.js

So I'm trying to do something like this :

root.rooting.ts

import {Routes, RouterModule} from '@angular/router';
const base = document.location.pathname.split('/')[1];
const paths = require('./' + base + '.js');

const appRoutes: Routes = paths;

export const routing = RouterModule.forRoot(appRoutes);

uk.js

export var paths = [
  { path: 'house',   loadChildren: 'app/+house/+house.module'},
  { path: '**', loadChildren: 'app/+404/+404.module'}
];

fr.js

export var paths = [
  { path: 'maison',   loadChildren: 'app/+house/+house.module'},
  { path: '**', loadChildren: 'app/+404/+404.module'}
];

es.js

export var paths = [
  { path: 'casa',   loadChildren: 'app/+house/+house.module'},
  { path: '**', loadChildren: 'app/+404/+404.module'}
];

How Can I implement this? Is it crazy to do that?

Upvotes: 0

Views: 929

Answers (1)

anshuVersatile
anshuVersatile

Reputation: 2068

NgModule will be called before constructor of your any component cause it is decorator but there is work around for it that is you can extend decorator for more read following article

http://myrighttocode.org/blog/typescript/angular2/decorators/angular2-custom-decorators

Upvotes: 1

Related Questions