与Angualrjs 1.3.9中的locationProvider问题,我仍然需要#来呼叫路由

时间:2017-04-19 16:33:55

标签: angularjs .htaccess

我遇到了locationProvider和routeProvider

的问题

在我的app.js中,我配置了locationProvider和routeProvider

在我的index.html中,我配置了基础href

这是我app.js的代码

var app = angular.module('bergenstem', ['ngRoute']).
config(['$routeProvider', '$locationProvider',function($routeProvider, $locationProvider){
    $locationProvider.html5Mode(true);
    $routeProvider.
        when("/",{templateUrl:"partials/list.html"}).
        when("/project",{templateUrl:"partials/test.html"}).
        when("/project2",{templateUrl:"partials/test2.html"}).
        when("/project3",{templateUrl:"partials/test3.html"}).
        when("/project4",{templateUrl:"partials/test4.html"}).
        when("/project5",{templateUrl:"partials/test5.html"}).
        otherwise({redirectTo:"/"});
    }])

这是index.html设置

<script type="text/javascript" src="https://code.angularjs.org/1.3.9/angular.js"></script>
<script type="text/javascript" src="https://code.angularjs.org/1.3.9/angular-route.js"></script>
<base href="/bergenstem/" />

当我使用http://dreamcpu.com/bergenstem/project时,我收到了404错误

当我使用http://dreamcpu.com/bergenstem/#/project时,它会重定向到http://dreamcpu.com/bergenstem/project并且数据会填充到ng-view

我创建了一个.htaccess文件,但它没有解决问题

任何想法:)感谢您的帮助

1 个答案:

答案 0 :(得分:0)

显然htaccess文件需要一段时间才能传播,所以现在它的工作很奇怪,在发布问题之前试图解决这个问题几个小时