我正嘗試使用角度路由在我的angularJS應用上執行路由。然而,當我嘗試在瀏覽器中加載/銷售時,什麼都沒有出現(我用'#'試過並得到相同的結果)。這裏是我的main.js文件:AngularJS在路由時給出'無法獲取/頁面'
'use strict';
/**
* @name Main module
* @description
*/
var app = angular.module('app', ['ngResource', 'ngRoute']);
app.config(['$routeProvider', '$locationProvider', function($routeProvider, $locationProvider){
$routeProvider.when('/sales', {
controller : 'SalesCtrl',
templateUrl : '/views/sales.html'
});
$locationProvider.html5Mode(true);
}]);
這裏是我的的index.html
<!doctype html>
<html class="no-js" lang="">
<head>
<meta charset="utf-8">
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>webapp</title>
<link rel="apple-touch-icon" href="apple-touch-icon.png">
<!-- Place favicon.ico in the root directory -->
<!-- build:css styles/vendor.css -->
<!-- bower:css -->
<!-- endbower -->
<!-- endbuild -->
<!-- build:css styles/main.css -->
<link rel="stylesheet" href="styles/main.css">
<!-- endbuild -->
<!-- build:js scripts/vendor/modernizr.js -->
<script src="/bower_components/modernizr/modernizr.js"></script>
<!-- endbuild -->
</head>
<body>
<!--[if IE]>
<p class="browserupgrade">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>
<![endif]-->
<!-- Google Analytics: change UA-XXXXX-X to be your site's ID. -->
<script>
(function(b,o,i,l,e,r){b.GoogleAnalyticsObject=l;b[l]||(b[l]=
function(){(b[l].q=b[l].q||[]).push(arguments)});b[l].l=+new Date;
e=o.createElement(i);r=o.getElementsByTagName(i)[0];
e.src='https://www.google-analytics.com/analytics.js';
r.parentNode.insertBefore(e,r)}(window,document,'script','ga'));
ga('create','UA-XXXXX-X');ga('send','pageview');
</script>
<!-- build:js scripts/vendor.js -->
<!-- bower:js -->
<script src="/bower_components/jquery/dist/jquery.js"></script>
<script src="/bower_components/modernizr/modernizr.js"></script>
<script src="/bower_components/angular/angular.js"></script>
<script src="/bower_components/angular-resource/angular-resource.js"></script>
<script src="/bower_components/angular-route/angular-route.js"></script>
<!-- endbower -->
<!-- endbuild -->
<!-- build:js scripts/main.js -->
<script src="scripts/main.js"></script>
<script src="scripts/services/sales.js"></script>
<script src="scripts/services/appconfig.js"></script>
<script src="scripts/controllers/sales.js"></script>
<!-- endbuild -->
<div ng-app="app">
<div ng-view></div>
</div>
</body>
</html>
我使用的角度1.6.1。 誰能告訴我我做錯了什麼?
任何控制檯錯誤?請提供日誌(如有) – Anirudha
使用$ locationProvider.html5Mode(false);如果設置爲true,它將從Url中刪除#,並且角度路由在沒有#前綴的情況下將不起作用。 – shiva
@Airirha在控制檯中有任何錯誤。 –