2015-09-01 119 views
1

我正在練習AngularJS並且遇到一個問題: ng-route即使我添加了angular-route.js也不起作用。AngularJS中的ng路由不起作用

這裏是我的app.js文件:

var app = angular.module('app', ['ngRoute']); 


app.config(['$routeProvider', function($routeProvider) { 
    $routeProvider 
    .when('/', { 
     templateUrl: 'views/intro.html' 
    }) 
    .when('game', { 
     templateUrl: 'views/game.html', 
     controller: 'TableController' 
    }) 
    .when('about', { 
     templateUrl: 'views/about.html' 
    }) 
    .otherwise({ 
     redirectTo: '/' 
    }); 
}]); 

,這裏是我的index.html

<!DOCTYPE html> 
<html> 
<head> 
    <title>Color Picking</title> 
    <meta name="author" content="pexea12"> 
    <meta charset="utf-8"> 
    <meta name="viewport" content="device=device-width, initial-scale=1.0"> 

    <!-- CSS --> 
    <link rel="stylesheet" href="css/style.css"> 

    <!-- Bootstrap --> 
    <link rel="stylesheet" href="css/bootstrap.min.css"> 
    <link rel="stylesheet" href="css/bootstrap-theme.min.css"> 

    <!-- Script --> 
    <script src="js/bootstrap/jquery-1.11.3.min.js"></script> 
    <script src="js/bootstrap/bootstrap.min.js"></script> 

</head> 
<body ng-app="app"> 
    <header> 
     <br> 
     <h2>Color Picking</h2> 
     <br> 
    </header> 

    <div id="main"> 
     <div ng-view></div> 
    </div> <!-- main --> 

    <!-- AngularJS --> 
    <script src="js/vendor/angular.min.js"></script> 
    <script src="js/vendor/angular-route.js"></script> 
    <script src="js/app.js"></script> 

    <!-- Services --> 
    <script src="js/services/ColorService.js"></script> 

    <!-- Factories --> 
    <script src="js/factories/RandomFactory.js"></script> 

    <!-- Controllers --> 
    <script src="js/controllers/TableController.js"></script> 

</body> 
</html> 

我的文件夾樹是: CSS(CSS文件,引導程序) JS(app.js,控制器,服務,工廠,...) views

我的網站與http://localhost:8080/,但不能與localhost:8080/about或localhost:8080 /遊戲一起使用。

我真的被困在這一點,找不到解決方案。

+0

你嘗試/ **時。 ('/遊戲'** ? – code

回答

1

我想以後有一個問題,你your're。當,應該是:

$routeProvider 
.when('/', { 
    templateUrl: 'views/intro.html' 
}) 
.when('/game', { 
    templateUrl: 'views/game.html', 
    controller: 'TableController' 
}) 
.when('/about', { 
    templateUrl: 'views/about.html' 
}) 
.otherwise({ 
    redirectTo: '/' 
}); 

你缺少你的路由