从外部文件加载路由器的路径 [英] Loading router's paths from external files

查看:61
本文介绍了从外部文件加载路由器的路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试构建一个可以在不同国家/地区以不同语言使用的应用程序. 这样做的目的是在每个国家/地区使用对SEO使用好的关键字的路径.

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.

加载的json文件取决于路径url: /uk, /fr, /es loads uk.js, fr.js or es.js

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?

推荐答案

NgModule将在任何组件的构造函数之前调用,原因是 装饰器,但有解决方法,您可以扩展装饰器以获取更多后续文章

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

这篇关于从外部文件加载路由器的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆