角度路线给出404错误

时间:2016-05-05 04:38:32

标签: javascript angularjs ngroute angularjs-ng-route

当我尝试点击我的角度路线时,我收到404错误,我不确定是什么错。我有这些链接:

<a href="/">Home</a>
<a href="/portfolio">Portfolio</a>
<a href="/about">About</a>
<a href="/travel">Travel</a>

这些路线在routes.js

中设置
app.config(function($routeProvider) {
    $routeProvider 
    .when('/', { 
        templateUrl: 'home.html',
        controller: 'mainController'
    })

    .when('/portfolio', { 
        templateUrl: 'portfolio.html',
        controller: 'mainController'
    })

    .when('/about', { 
        templateUrl: 'about.html',
        controller: 'mainController'
    })

    .when('/travel', { 
        templateUrl: 'travels.html',
        controller: 'mainController'
    });
});

我的理解是,当我点击<a href="/about"></a>时,控制器将在路由提供程序中查找/about。然后,它会看到模板about.html填充该请求,然后about.html将填入ng-view。不过,请求只是在http://localhost:8000/about给我404。我做错了什么?

没有错误,但是我的角度应用程序的其余部分仅供参考:

var app = angular.module('app', ['ngRoute']);
app.controller('mainController', ['$scope', '$routeParams', function($scope, $routeParams) { }]);

和HTML

    <div class="mountainSection">
        <div class="ang-wrap" ng-view></div>
    </div>

    <div class="controlPanel">
        <div class="buttonWrap">
            <div class="home button">
                <a href="/">Home</a>
            </div>
            <div class="divider">|</div>
            <div class="portfolio button">
                <a href="/portfolio">Portfolio</a>
            </div>
            <div class="divider">|</div>
            <div class="about button">
                <a href="/about">About</a>
            </div>
            <div class="divider">|</div>
            <div class="intl button">
                <a href="/travel">Travel</a>
            </div>
        </div>
    </div>

0 个答案:

没有答案