在asp.net中angular.js路由404找不到错误

时间:2015-09-05 10:06:39

标签: asp.net angularjs asp.net-web-api

我正在使用angular.js和asp.net webapi编写我的博客网站。我用angular.js做了url路由。当我点击网址但我得到404未找到错误。如何解决这个问题?

var blogSite = angular.module("blogSite", ["ngRoute"]);
blogSite.config(['$routeProvider', function ($routeProvider) {
$routeProvider
    .when("post/:post", {
        teplateUrl: 'blogpost.html',
        controller: 'blogPostController'
    })
    .otherwise({
        redirectTo: 'index.html'
    });
}]);

blogSite.controller("mainPageController", function ($scope, $http,     $routeParams) {
var url = baseUrl + "getpost";
$http.get(url)
    .success(function (data, status, headers, config) {
        if (data.length > 0) {
            $scope.LastBlogPosts = data;
        }
        else {
            $scope.LastBlogPosts = null;
        }
    })
    .error(function (data, status, headers, config) {
        console.log(status);
    });
});

blogSite.controller("blogPostController", function ($scope, $http, $routeParams) {
 $scope.TestMessage = "Test Message"
});

index.html页面

div ng-controller="mainPageController">
            <ul>
                <li ng-repeat="blogPost in LastBlogPosts">
                    <a href="post/{{blogPost.PostUrl}}" class="lastPostUrl mainPagePostTitle">{{blogPost.PostTitle}}</a>
                </li>
            </ul>
        </div>
    </div>
</div>
<div ng-view>

</div>

1 个答案:

答案 0 :(得分:0)

你的主播应该Computers来限制重定向,将#放在网址的开头会让你保持同一页面&amp;会让你留在SPA

#