2
我有angularjs和mvc4應用程序。爲了使用disqus,我啓用了hashbang和html5Mode url。AngularJS MVC 4路由,html5 hashbang網址
使用html5模式時,服務器端url重寫需要修復。否則整頁刷新會導致404錯誤。
我的應用程序的入口點是Index.chtml在家居控制器,它使用_layout.chtml
我的webconfig路線(捆綁和縮小。):
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',
}
}
];
}
========================================= ========================================
這個問題我上午有:
利用這種配置,所有這一切都只有1個深工作的路線沒有任何問題
,如:
/faq , /timeline
甚至刷新後,該URL被保留。
然而,對於URL的喜歡:
/thoughts/:articleid (2 deep)
造型爲整個應用程序,當我從這個網頁的刷新剝離出來。
我得到了同樣的問題,你有沒有找到一個解決方案? –
對不起,我還沒有任何想法..我正在使用1個深處...它在我的清單上查看,但還沒開始它.. :( – abhijitsinha89