试图添加一个简单的 404.html 模板,但由于某种原因它没有被渲染。在我的 app.routes.js 我尝试了以下
$routeProvider.when('/', {
templateUrl: '/templates/index.html',
controller: 'IndexCtrl'
}).otherwise({
templateUrl: '/templates/404.html'
})
我也尝试使用 redirectTo 如下,但它不起作用
.otherwise({
redirectTo: '/templates/404.html'
})
当我尝试在控制台中键入类似http://localhost:5000/aaaaaaaaaaaaa 的内容时,我看到 404 响应但未呈现模板。我需要调整控制器吗?
您可以使用特定视图为 404 创建特定路由/templates/404.html
。
然后,在otherwise()
方法调用中,您可以重定向到该路由/404
:
app.config(function ($routeProvider) {
$routeProvider
.when('/', {
templateUrl: 'templates/index.html',
controller: 'IndexCtrl'
})
.when('/404', {
templateUrl: 'templates/404.html'
})
.otherwise({
redirectTo: '/404'
});
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句