Loading router's paths from external files

♀尐吖头ヾ 提交于 2019-12-12 03:04:59

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/40867878/loading-routers-paths-from-external-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!