Add route to Ember Addon

女生的网名这么多〃 提交于 2019-12-12 10:46:28

问题


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!


回答1:


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




回答2:


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).



来源:https://stackoverflow.com/questions/39013075/add-route-to-ember-addon

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!