Ember应用程序的多路由器 [英] Multiple routers for an Ember app

查看:129
本文介绍了Ember应用程序的多路由器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



默认情况下,一个router.js将具有

 从ember导入Ember; 
从'../../config/environment'导入配置;

var Router = Ember.Router.extend({
location:config.locationType
});

export default Router.map(function(){
this.resource('sampleroute');

});

其他router.js将有

 从ember导入Ember; 
从'../../config/environment'导入配置;

var Router = Ember.Router.extend({
location:config.locationType
});

export default Router.map(function(){
this.resource('sampleroute2');

});

我需要的是让Ember应用程序读取默认的第二个路由器(router2.js)读取默认的router.js设置路由。

解决方案

您可以在函数中的seprate文件中定义ur路由,并导出功能像



page1.js

  export default function(){ 
this.route('page1');
}

page2.js

  export default function(){
this.route('page2');
}

然后将其导入到您的router.js文件中。

  import page1从page1开始; 
import page2从page2开始;

var Router = Ember.Router.extend({
location:config.locationType
});

Router.map(function(){
page1Routes.call(this);
page2Routes.call(this);
});

导出默认路由器;

您可以反复调用Router.map添加新路由。所以你可以以相同的方式导入其他路线。


Is it possible to have multiple router.js for an Ember app?

By default one router.js will have

import Ember from 'ember';
import config from '../../config/environment';

var Router = Ember.Router.extend({
  location: config.locationType
});

export default Router.map(function() {
  this.resource('sampleroute');

});

and other router.js will have

import Ember from 'ember';
import config from '../../config/environment';

var Router = Ember.Router.extend({
  location: config.locationType
});

export default Router.map(function() {
  this.resource('sampleroute2');

});

All I need is to make Ember application to read my second router(router2.js) which by default reads the default router.js to set up routes.

解决方案

You can define ur routes in seprate files inside a function and export that function like

page1.js

export default function() {
  this.route('page1');
}

page2.js

export default function() {
  this.route('page2');
}

Then import that into your router.js file.

import page1Routes from 'page1';
import page2Routes from 'page2';

var Router = Ember.Router.extend({
  location: config.locationType
});

Router.map(function() {
  page1Routes.call(this);
  page2Routes.call(this);       
});

export default Router;

You can call Router.map repeatedly to add new routes. So you can import ur other routes the same way.

这篇关于Ember应用程序的多路由器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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