在 $routeChangeError 上显示特定模板 [英] Display specific template on $routeChangeError
问题描述
我觉得没有办法做到这一点,但我认为问这个问题不会有什么坏处.我正在使用 route.resolve
在路由更改时检查当前用户状态,并确定他们是否有权访问该路由.假设它们不是,理想情况下我想简单地显示一个错误模板,而不是更改路由以指向错误页面.
I have a feeling there is no way to do this, but I figured it couldn't hurt to ask. I'm using route.resolve
to check the current user status when routes change and determine if they are authorized for that route. Assuming they aren't, ideally I'd like to simple display an error template rather than change routes to point to an error page.
显然后者更直接,但感觉不太对.是否可以以这种方式处理它,或者必须在这里获得更多创意.
Obviously the latter is more straightforward but it doesn't feel right. Is it possible to handle it this way or will have to get more creative here.
我考虑过的一个解决方案是在根模板中设置基于 $rooteScope.errorState 显示的指令.不是我最喜欢的解决方案,但暂时可行.
One solution I've considered is to have directives in the root template that show based on an $rooteScope.errorState is set. Not my favourite solution but a workable one for the time being.
推荐答案
ng-route
本身并不支持,你可以让它工作,但需要一些努力.但是,您可以使用 http://angular-route-segment.com/.
ng-route
doesn't natively support that, you could make it work but it requires some effort. However, you can use http://angular-route-segment.com/.
它通过 resolveFailed
选项增强了 ng-route
,因此您可以定义一组新的控制器和模板,以便在解析器失败时使用.
It enhances ng-route
with resolveFailed
option so you can define a new set of controller and template to use when resolver fails.
这篇关于在 $routeChangeError 上显示特定模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!