Multiple Routers For An Ember App
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
Solution 1:
You can define ur routes in seprate files inside a function and export that function like
page1.js
exportdefaultfunction() {
this.route('page1');
}
page2.js
exportdefaultfunction() {
this.route('page2');
}
Then import that into your router.js file.
import page1Routes from'page1';
import page2Routes from'page2';
varRouter = Ember.Router.extend({
location: config.locationType
});
Router.map(function() {
page1Routes.call(this);
page2Routes.call(this);
});
exportdefaultRouter;
You can call Router.map repeatedly to add new routes. So you can import ur other routes the same way.
Solution 2:
You can seperate your functions as blessenm shown above. But in that case you are continuing to keep a dependency to those files. And router.js is continuing to be a resource used by nearly all developers.
In addition to that answer: For each modul, you can generate a "modul-route.js" file exporting that function. Then by using instance-initializers, you can collect all this functions and run Router.map(...); function for all loaded files.
Post a Comment for "Multiple Routers For An Ember App"