Add route to Ember Addon

I am developing ember addon and I need to share one route between all applications using this addon, but I do not know how to do this or if it is possible. I am already adding routes to the addon, but an application that supports the addon does not see this. Any suggestions? Thanks!

+5
source share
2 answers

Yes it is possible. What you put in your addon application directory will be combined with the application directory for applications for applications. ( Resource ) Put your routes in the correct directories.

On the other hand, you need to add your routes to the router mapping. You can use instance initializers for this purpose. Also remember to put your instance initializers in the application directory. All you need to do in your initialization function is calling Router.map(...) . The code would be something like this:

 import Router from '../router'; function initialize(){ Router.map(function() { this.route('yourroute'); }); } 

ps: updated code

+5
source

In an Ember Engines RFC study, bcardarella asks: "What is the difference between Ember Engine and Ember Addon?" The discussion continues where ef4 says, "The only additions that cannot be made are to add routes to the router map." , (I think it means automatically in a unified way), however, an alternative and an example are given in the RFC stream:

https://github.com/emberjs/rfcs/pull/10#issuecomment-60504581 https://github.com/dockyard/ember-admin#usage


So you can use the workaround approach suggested by bcardarella. Or you can try Ember Engines (which also comes in the Addon package).

0
source

All Articles