[英]How to transition to route in Ember from global context?
I am integrating a chrome extension with an ember app. 我正在将chrome扩展程序与ember应用程序集成。 I have some chrome extension code in my app.js file: 我的app.js文件中有一些chrome扩展代码:
window.sendToExtension = (message, callback) => {
chrome.runtime.sendMessage(extensionId, message, (response) => {
console.log('got response from extension!!', response)
if (response.path) {
//Here I need to tell the ember app the transition to the given path
}
})
}
this
refers to window
so I can't just call this.transitionTo
. this
是指window
所以我不能只调用this.transitionTo
。 How can I transition to the route name the extension has told me to? 如何转换为扩展程序告诉我的路线名称?
I figured it out!! 我想到了!! All I had to do was add a beforeModel
hook to the application route that did window.applicationRouteInstance = this
and then I can access this globally, such as in my extension messaging code, to do applicationRouteInstance.transitionTo(response.path)
我要做的就是在执行window.applicationRouteInstance = this
的应用程序路由上添加一个beforeModel
钩子,然后可以全局访问该代码,例如在我的扩展消息传递代码中,以执行applicationRouteInstance.transitionTo(response.path)
Also there's the new App.visit api coming in 2.3 另外还有2.3版中的新App.visit API
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.