AngularJs (404) 页面重定向

AngularJs (404) page redirect

我是 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("otherwise", { url : '/404'...}) 如果路由器未找到与您的状态匹配的任何内容,它将重定向到其他状态