将路线添加到Ember Addon [英] Add route to Ember Addon

查看:90
本文介绍了将路线添加到Ember Addon的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发ember插件,我需要在使用该插件的所有应用程序之间共享一条路由,但是我不知道如何实现这一目标,甚至不知道是否有可能.我已经在addon中添加了路由,但是考虑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!

推荐答案

是可以的.您在插件的应用程序目录中输入的内容将与使用应用程序的应用程序目录合并. (资源),将您的路线放入正确的目录.

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.

另一方面,您需要将路由添加到路由器映射.为此,您可以使用实例初始化器.同样不要忘记将实例初始化程序放在应用程序目录中.在初始化函数中,您需要做的只是调用Router.map(...)该代码将是这样的:

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:代码已更新

这篇关于将路线添加到Ember Addon的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆