angularjs – 在webapi应用程序中使用角度路径

我不确定如何在web api应用程序中实现正确的角度路由.我可以使用这种方法打开页面:
http://localhost:52876/HTML/app/borrower.html

角度控制器加载精细,角度侧的所有功能都在那里.

现在,我希望能够使用ng-route以更好的视图打开视图,因此例如http://localhost:52876/HTML/app/borrower.html将成为
http://localhost:52876/borrower.

我在我的角度应用程序中使用的html文件中包含了ng-route.js文件.

同样在app.js我有这个:

'use strict';

var modules = [
    'app.controllers',
    'LoanAdminApplicationController',
    'ngCookies',
    'ngResource',
    'ngSanitize',
    'ngRoute',
    'ui.router',
    'LocalStorageModule',
    'angular-loading-bar'
];

var app = angular.module('app', modules);


app.config(function ($routeProvider, $locationProvider) {
    $locationProvider.html5Mode(true);
    $routeProvider.when("/home", {
        controller: "homeController",
        templateUrl: "/app/views/home.html"
    });

    $routeProvider.when("/login", {
        controller: "loginController",
        templateUrl: "/HTML/login.html"
    });

    $routeProvider.when("/signup", {
        controller: "signupController",
        templateUrl: "/app/views/signup.html"
    });

    $routeProvider.when("/register", {
        controller: "signupController",
        templateUrl: "/app/views/register.html"
    });

    $routeProvider.when("/refresh", {
        controller: "refreshController",
        templateUrl: "/app/views/refresh.html"
    });

    $routeProvider.when("/tokens", {
        controller: "tokensManagerController",
        templateUrl: "/app/views/tokens.html"
    });

    $routeProvider.when("/borrower", {
        controller: "borrowerController",
        templateUrl: "/HTML/app/borrower.html"
    });

    $routeProvider.otherwise({ redirectTo: "/home" });

});

html标记(我删除了内容):

<!DOCTYPE html>
<html ng-app="app">
<head>
</head>
<body ng-controller="BorrowerQuickQuoteApplication">


    <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
    <script src="/assets/js/jquery.min.js"></script>
    <script src="/assets/js/modernizr.js"></script>
    <!-- Include all compiled plugins (below), or include individual files as needed -->

    <script src="/assets/js/bootstrap.min.js"></script>
    <script src="/Scripts/angular.js"></script>
    <script src="/Scripts/angular-cookies.min.js"></script>
    <script src="/Scripts/angular-resource.min.js"></script>
    <script src="/Scripts/angular-sanitize.min.js"></script>
    <script src="/Scripts/angular-route.min.js"></script>
    <script src="/Scripts/angular-ui-router.min.js"></script>
<script src="/Angular/controllers.js"></script>
    <script src="/Angular/LoanApplicationController.js"></script>
    <script src="/Angular/services.js"></script>
    <script src="/Scripts/angular-local-storage.min.js"></script>
<script src="/Scripts/loading-bar.min.js"></script>

<script src="/Angular/app.js"></script>
</body>
</html>

知道我需要做些什么来使这个工作吗?

我应该修改RouteConfig.cs文件还是我还需要做其他事情?

谢谢,Laziale

最佳答案 例如,您没有使用文件名导航,因为您正在执行角度路径作业

  $routeProvider.when("/borrower", {
        controller: "borrowerController",
        templateUrl: "/HTML/app/borrower.html"
    });

当你去localhost:8080 / yourapp /借款人

你需要在index.html中使用ng-view

像这样

<div ng-view></div>

您的网页将在此处显示.

路由器看起来你要求借款人,它会带你到/HTML/app/borrower.html
您正在使用html五模式,这意味着您需要服务器端路由,因此它可以每次都落入index.html,因此您的网址可以没有哈希.

点赞