加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-mvc – 在将站点托管到IIS之后,AngularJS路由无法正常工

发布时间:2020-12-16 00:02:33 所属栏目:asp.Net 来源:网络整理
导读:我们在ASP.NET MVC框架中使用AngularJS创建SPA技术,从VS2013运行时,页面之间的AngularJS路由工作正常,但是在将应用程序托管到IIS7.5路由不起作用之后, 路由脚本: var appRoot = angular.module('main',['ngRoute','ngGrid','ngResource']); //Define the ma
我们在ASP.NET MVC框架中使用AngularJS创建SPA技术,从VS2013运行时,页面之间的AngularJS路由工作正常,但是在将应用程序托管到IIS7.5路由不起作用之后,

路由脚本:

var appRoot = angular.module('main',['ngRoute','ngGrid','ngResource']);     //Define the main module

    appRoot
        .config(['$routeProvider',function ($routeProvider) {
            //Setup routes to load partial templates from server. TemplateUrl is the location for the server view (Razor .cshtml view)
            $routeProvider
                .when('/home',{ templateUrl: '/home/main',controller: 'HomeController' }) .otherwise({ redirectTo: '/home' });
        }])
        .controller('RootController',['$scope','$route','$routeParams','$location',function ($scope,$route,$routeParams,$location) {
            $scope.$on('$routeChangeSuccess',function (e,current,previous) {
                $scope.activeViewPath = $location.path();
            });
        }]);

index.html的:

<li class="mt" data-ng-class="{active : activeViewPath==='/home'}">
                    <a href='#/home'>
                        <i class="fa fa-dashboard"></i>
                        <span>Dashboard Home</span>
                    </a>
                </li>


  <div class="col-lg-9 main-chart" ng-view="">
                </div>

项目结构:

解决方法

在IIS上运行它时会出现任何JS错误吗?

你在使用捆绑包吗?如果是,请检查是否因为缩小/捆绑创建添加而发生问题
BundleTable.EnableOptimizations = true;
在RegisterBundles方法中再次尝试在VS.

否则,我建议您在本地IIS上运行(右键单击项目,选项卡“Web”,“服务器”部分),看看它是否正常工作.

根据您的路由,您应该< base href =“@ Url.Content(”?/“)”/>在模板头部并使用$locationProvider.html5Mode(true)从网址中删除“#”;在路线配置.

如果以上都不是有用的,请在您的请求中添加更多详细信息.

祝你今天愉快,

阿尔贝托

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读