我想显示404错误页面,但我也想在位置保存错误的URL。
如果我会做这样的事情:
$urlRouterProvider.otherwise('404'); $stateProvider .state('404',{ url: '/404',template: error404Template });
有这种情况的解决方案。我们会使用1)一个ui-router本机特性和2)一个配置设置。
here可以观察到
here。
1)ui-router状态定义的本机特征是:
The
url
is not needed. State Could be defined without its representation in location.
2)配置设置为:
> otherwise()
for invalid routes,哪个参数不一定是一个带有默认url的字符串,但也可以是一个函数(cite):
path String | Function The url path you want to redirect to or a function rule that returns the url path. The function version is passed two params: $injector and $location
解决方案:这两个组合。我们会有没有url的状态和其他方式:
$stateProvider .state('404',{ // no url defined template: '<div>error</div>',}) $urlRouterProvider.otherwise(function($injector,$location){ var state = $injector.get('$state'); state.go('404'); return $location.path(); });
原文地址:https://www.jb51.cc/angularjs/144091.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。