我正在拦截error
卡在我的 ember 路线上。我在顶层这样做并从这个类继承我的所有路线。
我想要做的是,当服务器返回 401 未授权 响应,我想显示一条通知说用户未授权,并留在同一页面上。
到目前为止,我有这个:
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 ...
}
}
}
});
通知有效,但应用程序仍切换到新模板,该模板内容为空,因为用户无权查看它。
我希望我的应用程序保持在同一页面上,而不是转换到请求的页面。
如何?
最佳答案
我不确定,但你可以试试willTransition
:
willTransition: function(transition) {
// inspect transition object to see if the error ocurred
}
也许它会有所帮助:)
关于javascript - Ember - 防止路由错误转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30998689/