【问题标题】:AngularJs (404) page redirectAngularJs (404) 页面重定向
【发布时间】:2017-09-22 13:26:56
【问题描述】:

我是 AngularJs 的新手,我还没有理解 ui-router。 当他们访问错误的 URL 时,我试图将用户重定向到 404 页面。

如果我去 'siteURL/app/home' 会加载主页,如果我去 'siteURL/app/wrongURL' 我会被重定向到 404 页面,但如果我尝试访问 'siteURL/wrongURL' 我得到这个错误:

ENOENT:没有这样的文件或目录,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'
}); 

我做错了什么?

【问题讨论】:

    标签: javascript angularjs redirect angular-ui-router


    【解决方案1】:

    您可以尝试添加 .state("otherwise", { url : '/404'...}) 如果路由器没有找到任何与您的状态匹配的状态,它将重定向到其他状态

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-10-01
      • 2012-04-13
      • 2013-11-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多