AngularJs UI的路由器 - $ stateProvider不能看我的抽象状态 [英] AngularJs UI-Router - $stateProvider can't read my abstract state
问题描述
我有html5Mode问题。在我的MVC项目,我只有一个控制器
I have problem with html5Mode. In my MVC project I have only one controller
public class HomeController : Controller
{
public ActionResult Index()
{
return this.File("index.html", "text/html");
}
}
在我的角度项目我有两个途径,一个抽象的。
In my angular project I have two routes and one abstract.
angular.module('app').config(function ($urlRouterProvider, $stateProvider, $locationProvider) {
// if none of the above states are matched, use this as the fallback
$urlRouterProvider.otherwise('/app/articles');
$stateProvider
.state('app', {
url: "/app",
abstract: true,
templateUrl: "templates/blocks/layout.html",
controller: 'AppCtrl'
})
.state('app.articles', {
url: "/articles",
templateUrl: 'templates/articles.html',
controller: 'ArticlesCtrl'
})
.state('app.one-article', {
url: "/articles/:articleId",
templateUrl: 'templates/one-article.html',
controller: 'OneArticleCtrl'
});
// use the HTML5 History API
$locationProvider.html5Mode(true).hashPrefix('!');
});
这是在RouteConfig.cs
公共静态无效的RegisterRoutes(RouteCollection路线)
{
routes.MapRoute(
名字:文章
网址:应用程序/篇,
默认:新{控制器=家,行动=索引});
This is in the RouteConfig.cs public static void RegisterRoutes(RouteCollection routes) { routes.MapRoute( name: "articles", url: "app/articles", defaults: new { controller = "Home", action = "Index" });
routes.MapRoute(
name: "Default",
url: "{*url}",
defaults: new { controller = "Home", action = "Index" });
}
一切,当我从根导航工作正常。但是,当我将点击刷新按钮没有加载抽象状态。请帮助我如何解决这个问题。
Everything works fine when I'm navigating from the root. But when I will click refresh button abstract state is not loaded. Please help me how to solve this.
感谢
推荐答案
我解决了这个问题。
我的索引文件是在溶液中的根。相反的,我删除的index.html文件和创建MVC视图查看 - >首页 - > Index.cshtml。所有HTML是一样的index.html
My index file was in the root of the solution. Instead of that I removed that index.html file and created MVC view Views -> Home -> Index.cshtml. All HTML is the same as in index.html.
现在从控制器我使用
public ActionResult Index()
{
return this.View();
}
而不是这样的:
public ActionResult Index()
{
return this.File("index.html", "text/html");
}
下面是我的RouteConfig.cs
Here is my RouteConfig.cs
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "AngularCatchAllRoute",
url: "{*any}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
希望有人会发现这篇文章有用。
Hope someone will find this article useful.
波格丹
这篇关于AngularJs UI的路由器 - $ stateProvider不能看我的抽象状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!