[英]Ember - prevent transition on route error
I am intercepting the error
hook on my ember routes. 我在余烬路线上拦截了
error
钩子。 I am doing this on top level and inheriting all my routes from this class. 我正在顶层执行此操作,并从该类继承我的所有路由。
What I want to do is, when the server returns a 401 Unauthorized response, I want to display a notice saying the user is not authorized, and stay on the same page. 我想做的是,当服务器返回401未经授权的响应时,我想显示一条通知,指出用户未经授权,并停留在同一页面上。
So far I have this: 到目前为止,我有这个:
Ember.Route = Ember.Route.extend(InfinityRoute, {
actions: {
error: function(error){
if (error.status === 401) {
this.store.createRecord('notice', {
message: "You are not authorized to view this content. Sorry man."
});
// Some code here ...
}
}
}
});
The notice works, but the application still switches to the new template, which has empty content because the user does not have authorization to view it. 该通知有效,但是应用程序仍切换到新模板,该模板的内容为空,因为用户无权查看它。
I want my application to stay on the same page and not transition to the requested page. 我希望我的应用程序停留在同一页面上,而不要过渡到请求的页面。
How? 怎么样?
I'm not sure exactly but you can try willTransition
: 我不确定,但是您可以尝试
willTransition
:
willTransition: function(transition) {
// inspect transition object to see if the error ocurred
}
Maybe it'll help :) 也许会帮助:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.