Asp.net mvc AngularJs UI路由器-$stateProvider可以';我看不懂我的抽象状态
我对HTML5模式有问题。在我的MVC项目中,我只有一个控制器Asp.net mvc AngularJs UI路由器-$stateProvider可以';我看不懂我的抽象状态,asp.net-mvc,angularjs,angular-ui-router,Asp.net Mvc,Angularjs,Angular Ui Router,我对HTML5模式有问题。在我的MVC项目中,我只有一个控制器 public class HomeController : Controller { public ActionResult Index() { return this.File("index.html", "text/html"); } } 在我的角度项目中,我有两条路线和一个摘要 angular.module('app').config(function ($urlRouterProvi
public class HomeController : Controller
{
public ActionResult Index()
{
return this.File("index.html", "text/html");
}
}
在我的角度项目中,我有两条路线和一个摘要
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
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" });
}
当我从根开始导航时,一切正常。但是当我点击刷新按钮时,抽象状态没有加载。请帮我解决这个问题
感谢使用最新的angular和
$locationProvider.html5Mode()
设置,我们也可以选择
1) 我解决了这个问题
我的索引文件位于解决方案的根目录中。相反,我删除了index.html文件并创建了MVC视图->主页->index.cshtml。所有HTML与index.HTML中的相同
现在从我使用的控制器中开始
public ActionResult Index()
{
return this.View();
}
与此相反:
public ActionResult Index()
{
return this.File("index.html", "text/html");
}
这是我的路线图
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 }
);
}
希望有人会觉得这篇文章有用
博格丹感谢您的快速回复。在我改为document.write(“”)后,我得到了一个空页面,其中有太多角度错误。可能问题出在我的IIS配置中?服务器设置有一些重要的细节:顺便说一句,我使用了document.write,因为在plunker上它是必须的,url正在更改。在您的情况下,它可能是
base=“/”
。。。测试它,玩。。。普朗克应该会再次感谢你。我的服务器已配置,我更改为base=“/”并且再次出现相同的问题。这真是一种奇怪的行为。当angular重定向我时,一切正常,当我手动转到想要的链接布局时,所有的脚本和css都没有加载。很难在plunker上模拟这个解决方案。请写信给我。nicovski@yahoo.com. 我将在我的项目中展示。谢谢这篇文章被修改为更容易理解。
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 }
);
}