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
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: GitHub - DockYard/ember-admin: Admin backend for ember-cli projects
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 ?
Not sure I understand the question but if you use ember-cli you can write something like this:
import EmberRouter from '@ember/routing/router';
import config from './config/environment';
export default class Router extends EmberRouter {
location = config.locationType;
rootURL = config.rootURL;
}
Router.map(function () {
this.route('about');
this.route('secret');
this.route('login');
this.route('posts', function () {
this.route('post', { path: ':post_id' });
});
this.route('authors', function () {
this.route('author', { path: ':author_id' });
});
});
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 ?
It’s not supported in Ember yet, but the core team is actively working on it in this addon: Support Lazy Loading engines · Issue #51 · ember-engines/ember-engines · GitHub