Asp.net mvc AngularJS MVC 4路由,html5 hashbang URL

Asp.net mvc AngularJS MVC 4路由,html5 hashbang URL,asp.net-mvc,angularjs,Asp.net Mvc,Angularjs,我有angularjs和mvc4应用程序。为了使用disqs,我启用了hashbang和HTML5模式url 在html5模式下,服务器端url重写需要修复。否则,整页刷新将导致404错误 我的应用程序的入口点是home controller中的Index.chtml,它使用_layout.chtml(用于捆绑和缩小) 我的网络配置路线是: routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute(

我有angularjs和mvc4应用程序。为了使用disqs,我启用了hashbang和HTML5模式url

在html5模式下,服务器端url重写需要修复。否则,整页刷新将导致404错误

我的应用程序的入口点是home controller中的Index.chtml,它使用_layout.chtml(用于捆绑和缩小)

我的网络配置路线是:

routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapRoute(
            name: "Default",
            url: "{*url}",
            defaults: new { controller = "Home", action = "Index"},
            namespaces: new[] { "Flashspark.Controllers" });
我的AngularJS配置是:

(function () {
'use strict';

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

// Collect the routes
app.constant('routes', getRoutes());

// Configure the routes and route resolvers
app.config(['$routeProvider', '$locationProvider', 'routes', routeConfigurator]);
function routeConfigurator($routeProvider,$locationProvider, routes) {

    routes.forEach(function (r) {
        $routeProvider.when(r.url, r.config);
        $locationProvider.html5Mode('true').hashPrefix('!');
    });
    $routeProvider.otherwise({ redirectTo: '/' });

}

// Define the routes 
function getRoutes() {
    return [
        {
            url: '/',
            config: {
                templateUrl: 'app/thoughts/thoughts.html',
                title: 'thoughts',
                settings: {
                    nav: 1,
                    content: '<i class="fa fa-book"></i> Thoughts'
                }
            }
        }, {
            url: '/faq',
            config: {
                title: 'faq',
                templateUrl: 'app/faq/faq.html',
                settings: {
                    nav: 2,
                    content: '<i class="fa fa-info"></i> FAQ'
                }
            }
        },
         {
             url: '/timeline',
             config: {
                 templateUrl: 'app/timeline/timeline.html',
                 title: 'timeline',
                 settings: {
                     nav: 3,
                     content: '<i class="fa fa-arrows-h"></i> Timeline'
                 }
             }
         },
          {
              url: '/about',
              config: {
                  templateUrl: 'app/about/about.html',
                  title: 'contact',
                  settings: {
                      nav: 4,
                      content: '<i class="fa fa-list fa-1x"></i> About'
                  }
              }
          },
          {
              url: '/thoughts/:article',
              config: {
                  templateUrl: 'app/article/article.html',
                  title: 'article',
              }
          }

    ];
}
即使在刷新后,url也会保留

但是,对于URL,例如:

/thoughts/:articleid (2 deep)

当我从该页面刷新时,整个应用程序的样式将被剥离。

您需要为
想法创建一个默认路径。

{
  url: '/thoughts',
  config: {
    templateUrl: 'app/article/article.html',
    title: 'article',
  }
}

我遇到了同样的问题,你找到解决方案了吗?对不起,还没有想法..我正在使用1 deep everywhere…它在我的列表中要检查,但尚未开始(
{
  url: '/thoughts',
  config: {
    templateUrl: 'app/article/article.html',
    title: 'article',
  }
}