Multiple routers files for an Ember app


#1

hi

I am working on modular application ,in the core module,ember folder exists base on structural of ember cli ,so the “router.js” file is available. with this code :

import Ember from ‘ember’;

import config from ‘./config/environment’;

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

Router.map(function() { });

export default Router;


but I want, when other modules is added to Core module in runtime, each module is inject own separate routes


#2

I don’t know how to do it on runtime but you can import routes like this:

import adminRouter from 'ember-admin/router';

Router.map(function() {
  adminRouter(this);
});

See: https://github.com/dockyard/ember-admin


#3

Thanks for the answer.

But My question is : Splitting routes into multiple files in a large application.In each module, a router file exists. but this path is not detected.

when writing program by es5, there is a global variable in core module. for example


window.Arad = Ember.Application.create({});

the global variable is Arad .

in other modules, by this global variable ,each module adds its routes to ember app with the following code


Arad.Router.map(function () {

this.route("testInvitationModule", function () {
    this.route("index");
    this.route('invitation', function () {
        this.route("index");
        this.route("about", function () {
            this.route("index");
            this.route("test");
        });
    });
});

});

But I do not know how to do this in es6 ?


#4

Not sure I understand the question but if you use ember-cli you can write something like this:


#5

Perhaps my question is:

How to call or load Multiple routers files for an ember app, then after call or load Multiple routers files, all Routers to be added to the ember app ?

Or

How to add dynamic routing in ember app ?

Or

dependncy injection for inject router to ember app ?


#6

It’s not supported in Ember yet, but the core team is actively working on it in this addon: https://github.com/dgeb/ember-engines/issues/51


#7

thanks for your answer