【问题标题】:AngularJs view do not load when i direct paste URL当我直接粘贴 URL 时,AngularJs 视图不加载
【发布时间】:2017-02-01 01:59:36
【问题描述】:

我是 Angular 的新手,我使用 angularJs(用于路由的 ngRoute)创建了一个应用程序,它与从一个页面到另一个页面的链接完美配合,但问题是当我直接粘贴 url 或为浏览器 url 栏编辑它时浏览器显示 “找不到这个页面” 我使用 $locationProvider html4 模式从 url 中删除 #。所以请帮助我有人是因为这个还是什么?

这是我的路线

angular
.module("myApp", ["ngSanitize", "ngLoadingSpinner", "ngRoute"])
.config(function ($locationProvider, $routeProvider) {

$routeProvider
    .when('/' , {
    templateUrl: "templates/index.tpl.html"
})
    .when('/work' , {
    templateUrl: "templates/work.tpl.html"
})
    .when('/work/:id' , {
    templateUrl: "templates/workDetail.tpl.html"
})
    .otherwise({redirectTo:'/'});


$locationProvider.html5Mode(true);

});

和 URl 看起来像这样 http://127.0.0.1:8080/work/1

【问题讨论】:

  • 你能把你的路线和示例网址一起发布吗?
  • 已编码添加到我的问题中。请检查
  • 兄弟已添加。

标签: javascript angularjs http views


【解决方案1】:

听起来您需要设置您的服务器以在您直接导航到这些路由时正确地提供索引文件。即使您转到非根 URL,这也会导致服务器为 index.html 提供服务。

类似的设置应该可以工作。 (假设您使用的是 Nginx) https://gist.github.com/calebwoods/5e88b5e323d55ad71195

特别注意这个块:

location / {
    try_files $uri /index.html;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-06-16
    • 2021-12-20
    • 1970-01-01
    • 2017-11-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多