Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add route to Ember Addon

i'm developing ember addon and i need to share one route between all applications that use this addon but i don't know how to achieve that or if it's even possible. Already i've add routes in addon, but application that counsume addon, doesn't see this. Any suggestions? Thanks!

like image 719
Michał Marcinkowski Avatar asked Aug 18 '16 08:08

Michał Marcinkowski


2 Answers

Yes it is possible. What you put in your addon's app directory will be merged with consuming applications' app directory. (Resource) Put your routes into 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 doesn't forget to put your instance-initializers in your app directory. All you need to do in your initializer function is calling Router.map(...) The code will be something like that:

import Router from '../router';

function initialize(){
  Router.map(function() {
    this.route('yourroute');
  });
}

ps: code updated

like image 200
ykaragol Avatar answered Nov 09 '22 20:11

ykaragol


In an Ember Engines RFC discussion, bcardarella, asks, "What's the difference between an Ember Engine and Ember Addon"? The discussion continues where ef4 says, "The only thing addons can't do is add routes to the router map.", (I think he means in an automatically merged way), however an alternative and example is given in the RFC thread:

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


Thus you can use the workaround approach suggested by bcardarella. Or, you can try Ember Engines (which is also delivered in an Addon package).

like image 1
Michael R Avatar answered Nov 09 '22 19:11

Michael R