【问题标题】:Angularjs routing cannot get '/webpage'Angularjs路由无法获取'/webpage'
【发布时间】:2017-01-13 01:02:41
【问题描述】:

首先让我对格式设置表示歉意。我用手机发帖。

在我的 /public/js/app.js 我有这个

var app = angular.module("myApp", ["ngRoute"]);
app.config(function($routeProvider) {
    $routeProvider
    .when("/", {
        templateUrl : "/public/views/index.html"
    })
    .when("/packages", {
        templateUrl : "/public/views/packages.html"
    })
    .when("/contactus", {
        templateUrl : "/public/views/contactus.html"
    })
    .when("/signup", {
        templateUrl : "/public/views/signup.html"
    })
. otherwise({
redirectTo: "/";
});
});

在我的 /public/index.html

下面有这个

<html ng-App="myApp">
// All the angular script files including app.js
<body>
<div ng-view></div>

我所有的 HTML 文件都位于 /public/views/

我得到“无法 GET '/contactus'”

或者任何不是索引的网页。

有什么帮助吗?

【问题讨论】:

  • 在您的浏览器中,您要访问 URL '/contactus' 还是 URL '/#/contactus'?您可能需要使用后者。
  • 我要在浏览器中访问 /contactus

标签: angularjs-routing


【解决方案1】:

应该都是小写的 ng-app 并且你有 ;否则反对。你能试试那个。

【讨论】:

  • 正如你上面提到的评论,如果你想删除#标签,那么你需要有$locationProvider.html5Mode(true)。您的代码将如下所示。 app.config(function($routeProvider, $locationProvider) { //你的路由路径 $locationProvider.html5Mode(true); });并在头部标签
猜你喜欢
  • 2016-06-12
  • 1970-01-01
  • 2017-08-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-04-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多