角$ locationProvider的ASP.NET MVC路由 [英] Angular $locationProvider with ASP.NET MVC routing

查看:87
本文介绍了角$ locationProvider的ASP.NET MVC路由的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我处理使用ASP.NET MVC(使用RouteCollection类)路由。但我的前端是用棱角分明,在一些地方我想用角的位置$更改URL,我希望它支持HTML5,所以我说这行我module.config:

I'm handling routing using ASP.NET MVC (using RouteCollection class). But my front end is written in angular and at some places I want to change url using Angular's $location and I want it to support HTML5, so I added this line to my module.config :

$locationProvider.html5Mode(true);

但此后似乎我的路由已经被角处理。

But since then it seems that my routing has been handled by Angular.

例如我的SPA是mysite.com/user而且我想用角的位置$改变URL(所以当例如用户点击选项卡链接的变化而无需重新加载到mysite.com/user/tab~~V)。

For example my SPA is on mysite.com/user and there I want to change url using Angular's $location (so when for example users click tab url changes to mysite.com/user/tab without reloading).

但是,当用户从页面导航到任何其他(例如mysite.com/other)我想通过ASP.NET MVC的路由处理。

But when user navigates from that page to any other (for example mysite.com/other) I want that handled by ASP.NET MVC's routing.

现在发生的事情是,我的网址更改mysite.com/other~~V但网站不导航到该页面,即MVC路由不处理的变化。

What now is happening is that my url changes to mysite.com/other but website doesn't navigate to that page, i.e. MVC routing doesn't handle change.

修改

我没有在角定义的任何路线,我所有路由都在服务器端和服务器端的路由定义只是我弯下身子后加入 $ locationProvider.html5Mode(真)的工作;

I don't have any routes defined in Angular, all my routes are defined on server side and server side routing just stooped working after I added $locationProvider.html5Mode(true);

推荐答案

没有遗憾的是没有。如果你的角SPA是在 foo.com 与HTML 5模式托管, foo.com/spaRoute1 会打你ASP.Net服务器,并期望找到这条路线(可能控制器= SpaRoute1行动=指数)。

No unfortunately not. If your angular SPA is hosted at foo.com with HTML 5 mode on, foo.com/spaRoute1 will hit your ASP.Net server and expect to find that route (likely controller=SpaRoute1 action=Index).

您将需要设置你的默认路由始终解析到控制器/动作,负责提供您的SPA。所有的定义时,你需要的任何其他途径而不是特定于您的SPA。

You will need to set your default route to always resolve to the controller/action that is responsible for serving up your SPA. All while defining any other routes that you need which are not specific to your SPA.

这篇关于角$ locationProvider的ASP.NET MVC路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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