我想用MEAN棧構建我的第一個web應用,並且我正面臨着Angular路由的問題。角度路由非工作
<!-- public/index.html -->
<!DOCTYPE HTML>
<html lang="en" content-type="text/css">
<head name="viewport" content="width=device-width, initial-scale=1">
<meta charset="UTF-8">
<base href="/">
<title>Trova colori in tinta</title>
<!-- CSS -->
<link rel="stylesheet" href="libs/bootstrap/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="css/style.css"> <!-- custom styles -->
<link rel="stylesheet" href="normalize.css"> <!-- custom styles -->
<!-- JS -->
<script type="text/javascript" src="libs/angular/angular.min.js"></script>
<script type="text/javascript" src="libs/angular-route/angular-route.min.js"></script>
<!-- ANGULAR CUSTOM -->
<script type="text/javascript" src="js/controllers/MainCtrl.js"></script>
<script type="text/javascript" src="js/controllers/NerdCtrl.js"></script>
<script type="text/javascript" src="js/services/NerdService.js"></script>
<script type="text/javascript" src="js/appRoutes.js"></script>
<script type="text/javascript" src="js/app.js"></script>
</head>
<body >
<div class="container" ng-app="sampleApp" ng-controller="NerdController">
<!-- HEADER -->
<nav class="navbar navbar-default" >
<div class="navbar-header">
<a class="navbar-brand" href="/">Colori</a>
</div>
<!-- LINK TO OUR PAGES. ANGULAR HANDLES THE ROUTING HERE -->
<ul class="nav navbar-nav">
<li><a href="/nerd">Nerds</a></li>
<li><a href="/lacci">lacci</a></li>
</ul>
</nav>
<div class="container-fullwidth"></div>
<!-- ANGULAR DYNAMIC CONTENT -->
<div ng-view></div>
</div>
</body>
</html>
當我點擊「書呆子」或「lacci」鏈接它不顯示這些頁面。
這裏是文件appRoute.js
angular.module('appRoutes', []).config(['$routeProvider', '$locationProvider', function($routeProvider, $locationProvider) {
$routeProvider.when('/', {
templateUrl: '/public/views/home.html',
controller: 'MainController'
}) // nerds page that will use the NerdController
.when('/nerds', {
templateUrl: '/public/views/nerd.html',
controller: 'NerdController'
}).when('/lacci', {
templateUrl: '/public/views/lacci.html',
}).otherwise({ redirectTo: "/home" });
$locationProvider.html5Mode(true);}]);
兩個文件是在型動物的文件夾。 我在哪裏錯了?
我可能是錯的,但我認爲對的'href's錨標籤需要'#'在前面[W3Schools角路由](https://www.w3schools.com/angular/angular_routing.asp)像'Nerds' –
@SenSok他沒有使用ui路由器在這裏,所以他做不需要它 –
@michele import ngRoute in this like'angular.module('appRoutes',['ngRoute'])' –