角度为html5mode的错误404

时间:2016-09-20 19:29:33

标签: angularjs iis html5mode

我尝试使用ui-router创建简单的角度网页,以便在HTML5Mode上进行路由。我使用visual studio和IIS expres作为服务器

的index.html

<!doctype html>
<html ng-app="questApp">
<head>
    <title>First Page</title>   
    <base href="/">
    <meta charset="utf-8">
    <meta name="fragment" content="!" />
    <script src="lib/angular.min.js"></script>
    <script src="lib/angular-route.min.js"></script>
    <script src="scripts/app.js"></script>
    <script src="controllers/conroller1.js"></script>
    <script src="controllers/conroller2.js"></script>
    <script src="controllers/indexConroller.js"></script>
    <script src="controllers/main.js"></script>
</head>
<body>
    <div class="container">              
        <div class="row col-xs-12">
            <div class="col-xs-3">
                <div class="row"><a href="/index2">index</a></div>
                <div class="row"><a href="/page1">view1</a></div>               
            </div>
            <div class="col-xs-9">          
                <ng-view>                  
                </ng-view>
            </div>
        </div>
            </div>
</body>
</html>

app.js

var testApp = angular.module('questApp', ["ngRoute"])
        .config(function ($routeProvider, $locationProvider) {

        $routeProvider.when('/index2',
        {
            templateUrl: 'views/indexView.html',
            controller: 'indexConroller'
        })
         .when('/page1',
        {
            templateUrl: '/views/view1.html',
            controller: 'conroller1'
        })       
        .when('/',
        {
            templateURL: 'views/main',
            controller: function () {
                console.log('views/main');
            },
        })
         .otherwise({
             redirectTo: '/'
         });        

        $locationProvider.html5Mode(true).hashPrefix("!");
    });

$locationProvider.html5Mode(true);

页面index.html有标记

<base href="/">

网址工作正常,但当我刷新页面时,我得到错误404.0 - 未找到。 你有什么想法,这会导致什么?

0 个答案:

没有答案