我是 AngularJs 的新手,我还没有理解 ui-router。 当用户访问错误的 URL 时,我尝试将他们重定向到 404 页面。
如果我转到“siteURL/app/home”,则会加载主页,如果我转到“siteURL/app/wrongURL”,我会被重定向到 404 页面,但如果我尝试访问“siteURL/wrongURL”,则会加载收到此错误:
ENOENT: no such file or directory, lstat '/path_to_website_folder/node_modules/cloudcmd/wrongURL/'
而不是被重定向到 404 页面。
此外,如果我尝试访问“siteURL/app”,我希望被重定向到“siteURL/app/home”。 这是我写的代码:
$urlRouterProvider.otherwise("/app/404");
$stateProvider.state('app', {
url: "/app",
templateUrl: getPath('app.html')
})
.state('app.home', {
url: "/home",
templateUrl: getPath('app.home.html'),
title: 'Home',
keywords: "keywords",
description: "description"
})
.state('app.404', {
url: "/404",
templateUrl: getPath('app.404.html'),
title: '404'
});
我做错了什么?
最佳答案
您可以尝试添加
.state("否则", { url : '/404'...})
如果路由器没有找到任何与您的状态匹配的内容,它将重定向到其他状态
关于javascript - AngularJs (404) 页面重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46365940/