ngRoute不工作 [英] ngRoute not working

查看:276
本文介绍了ngRoute不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的脚本是:

的index.html

<!DOCTYPE html>
<html ng-app="myApp">
<head>
    <title>My Application</title>
</head>
<body>
    <div ng-view></div>

    <script src="/assets/vendor/angular/angular-1.2.16.min.js"></script>
    <script src="/assets/vendor/angular/extras/angular-route.js"></script>
    <script src="/assets/myapp/myApp.js"></script>
</body>
</html>

myApp.js

(function () {
    angular.module('myApp', ['ngRoute'])
           .config(['$routeProvider', '$locationProvider', function ($routeProvider, $locationProvider) {
               $routeProvider.
                 when('/', {
                     template: '<h1>Home</h1>',
                     controller: function () {
                         console.log('Home');
                     }
                 }).
                 when('/books', {
                     template: '<h1>Books</h1>',
                     controller: function () {
                         console.log('Books');
                     }
                 });
               $locationProvider.html5Mode(true);
               console.log('routes configured');
           }]);
})();

我已经浪费了很多时间试图找出这个问题可能是没有运气的东西。我失去了一些愚蠢的?在此先感谢您的帮助。

I've wasted a lot of time trying to figure out what the problem might be with no luck. Am I missing something silly? thanks in advance for the help.

推荐答案

您在托管服务器的根目录下您的应用程序?如果没有,那么你需要在你的脑袋标签使用下面的标签。

Are you hosting your application in the root of your server? If not, then you will need to use the tag below in your head tag.

<base href="PATH_HERE" />

另外,你能注释掉$ locationProvider.html5Mode(真)线,让你的应用程序中的散列工作第一路由模式?

In addition, can you comment out the $locationProvider.html5Mode(true) line and get your app working in hash routing mode first?

这篇关于ngRoute不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆