作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我们正在开发一个 angularjs 应用程序,用户可以在其中将他或她的个人资料作为简历发布。
例如,如果用户有已发布的个人资料,则以下 url 有效:
www.page.com/public/johnsmith
但是如果出现
www.page.com/public/johnsmith2345
这不是公开的个人资料,我想显示 404 页面。问题是,由于 Angular 的路由,我必须重定向到 404 页面,因此 url 将被重写为
www.page.com/404.
维护原始 url 甚至使其在 IE9 中工作的正确实现是什么?
最佳答案
据我所知,执行此操作的唯一方法是在 Controller / View 中处理此问题。例如
$routeProvider.when('/public/:user',
{
templateUrl: 'profile.html',
controller: 'profileCtrl',
resolve: {
userProfile: {
//Try and load the user's profile. Resolve null if the profile can't be found
}
}
}
);
var profileCtrl = function($scope, userProfile) {
$scope.userProfile = userProfile;
}
个人资料.html:
<div ng-if="!userProfile">
<div ng-include="404page.html"></div>
</div>
<div ng-if="userProfile">
... Profile view here
</div>
关于javascript - 如何在AngularJS中维护404页面的url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24206552/
我是一名优秀的程序员,十分优秀!