AngularJS路由网站后不工作托管到IIS [英] AngularJS routing not working after site hosted into IIS

查看:178
本文介绍了AngularJS路由网站后不工作托管到IIS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在创建使用ASP.NET MVC框架AngularJS SPA技术,AngularJS页面之间的路由是当它从VS2013运行工作正常,但在托管应用程序IIS7.5路由不工作后,

We are creating SPA technique using AngularJS in ASP.NET MVC framework,AngularJS routing between pages are working fine when it's run from VS2013,but after hosting the application in to IIS7.5 routing not working,

路由脚本:

   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:

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>

项目结构:

推荐答案

你得到任何JS错误,当您在IIS上运行呢?

do you get any JS error when you run it on IIS?

您使用的包?如果是这样的检查,如果发生问题,因为微小/包创建的加入
BundleTable.EnableOptimizations = TRUE;
RegisterBundles 方法和VS重试。

are you using bundles? If so check if the problem happens because of minification/bundle creation adding BundleTable.EnableOptimizations = true; in RegisterBundles method and trying again in VS.

否则我建议你在本地IIS中运行(项目上点击右键,选项卡的网络一节服务器),看看它是否工作正常。

Otherwise I suggest you to run on local IIS (right click on project, tab "Web",section "Servers") and see if it works correctly.

根据你的路由你应该&LT的;基本href =@ Url.Content(〜/)/&GT; 模板头,摆脱使用#从网址 $ locationProvider.html5Mode(真); 路由配置

Depending of your routing you should <base href="@Url.Content("~/")" /> in template head and get rid of "#" from url using $locationProvider.html5Mode(true); on route configuration.

如果以上都不是有用的,请详细信息添加到您的要求。

If none of the above are useful please add more details to your request.

有一个愉快的一天,

阿尔贝托

这篇关于AngularJS路由网站后不工作托管到IIS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆