0
votes

I am currently writing a big Ember.js application. I know Ember.js is quite monolithic but I wanted to drift a bit from this and create modules that I would plug in my application.

I have no problem with component-only modules or those kind of things. My big issue is to import new routes in my Ember-cli application.

Usually I would have my App.Router and I could create App.xxxRoute whether I define the route in app/routes/my-route.js or in lib/myModule/routes/my-route.js.

With the Ember-cli ES6 Module syntax, the routes taken into account are only the ones from the app/routes folder and as there is no global scope anymore, I can't attach the routes coming from my module to my main application. This is a bit of a pain.

I have tried a lot of things, ranging from trying to add my routes to the Ember.Router.router.recognizer manually (does not work) to creating the routes files in app/routes and exporting the ones from my modules for each of one of them (but it creates a lot of useless files).

The easiest solution would be to be able to add a directory to the ember-cli path loader or whatever it's called but I'm open to any suggestion.

Thanks a lot.

1
Is the pod structure of Ember CLI pod structure what you're looking for? I believe this will support what you're looking for.Mike Wilson
Thanks but I know about pods and that's not what I am lookin for at all, I'm really talking about fully detached modules, living in other repositories and added via bower.Gabriel Dehan
Im not sure but may be this addon will give you an idea of how its done. github.com/diogoko/ember-cli-auto-routerblessenm
I think you want to look into building ember cli addons, they can add routes (and other stuff) to the host app.Sam Selikoff
Thanks for the insights I'll look into it. It's really cool having some code to look at :)Gabriel Dehan

1 Answers

1
votes

The approach that I would take is to build an add-on, as mentioned in the comments.

And maybe, depending on your needs, add some initializers that inject objects and anything you like to all your routes or controllers in your app.

See: Dependency Injection & Service Lookup

For an example of an add-on that uses initializers you can check Ember Simple Auth