【发布时间】:2014-02-24 21:08:01
【问题描述】:
我想从“/”提供我的 AngularJS SPA,因此我禁用了默认路由并正在使用
// this action does not 'fire' due to Angular's routing...
routes.MapRoute(
name: "Test",
url: "Test",
defaults: new { controller = "Home", action = "Test" },
namespaces: new[] { "My.WebApp.Controllers" }
);
// Index view has no layout and contains Angular SPA
routes.MapRoute(
name: "AngularJs-SPA",
url: "{*catchall}",
defaults: new { controller = "Home", action = "Index" },
namespaces: new[] { "My.WebApp.Controllers" }
);
我也在使用以下 Angular 应用程序配置块
.config(['$routeProvider', '$httpProvider', '$locationProvider', function ($routeProvider, $httpProvider, $locationProvider) {
$routeProvider.otherwise({ redirectTo: '/404' });
$httpProvider.defaults.headers.common["X-Requested-With"] = "XMLHttpRequest";
$locationProvider.html5Mode(true);
}])
我的问题是,我还能以某种方式拥有一个响应 MVC 操作的常规服务器端页面(在本例中为 /Home/Test)吗? 我看到的问题是 Angular 接管了路由,即使我定义了额外的路由(在 Angular 路由之前或之后),Angular 也将其视为“否则”路由......
很少(不受欢迎的)解决方案
- 在 MVC 中指定每个 Angular 应用程序路由,而不是 {*catchall}
- 将 angular spa 移动到非 root 操作(例如 /app)
【问题讨论】:
标签: asp.net-mvc angularjs asp.net-mvc-routing single-page-application angularjs-routing