【发布时间】:2015-11-30 08:24:53
【问题描述】:
当您访问不存在的页面时,我熟悉返回 404 作为 HTTP 状态代码。当您构建静态网站时,它运行良好且有意义,但在 Angular 中则不同。
假设我访问了/blah,但它不在我的路线列表中 - 然后我重定向到/not-found。但是,假设我访问了一个有效的 URL,例如 /stuff/123,但我的后端中不存在对象 Stuff123。然后我应该手动在我的
StuffController 与 $location.path('/not-found')?
这是我现在的配置:
app.config(['$routeProvider', function ($routeProvider) {
$routeProvider
.when('/stuff/:id', {
templateUrl: '/views/stuff.html',
controller: 'StuffController'
})
.when('/not-found', {
templateUrl: '/views/not-found.html'
})
.otherwise({
redirectTo: '/not-found'
});
});
另外,在 Angular 中返回 404 有意义吗?如果是这样,那我该怎么做呢?
【问题讨论】:
-
是的,您可以将其添加到您的控制器中。
标签: angularjs model-view-controller http-status-code-404