asp.net mvc - AngularJs UI-Router - $stateProvider can't read my abstract state -
i have problem html5mode. in mvc project have 1 controller
public class homecontroller : controller { public actionresult index() { return this.file("index.html", "text/html"); } }
in angular project have 2 routes , 1 abstract.
angular.module('app').config(function ($urlrouterprovider, $stateprovider, $locationprovider) { // if none of above states matched, use 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 html5 history api $locationprovider.html5mode(true).hashprefix('!'); });
this in 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 root. when click refresh button abstract state not loaded. please me how solve this.
thanks
i solved problem.
my index file in root of solution. instead of removed index.html file , created mvc view views -> home -> index.cshtml. html same in index.html.
now in controller i'm using
public actionresult index() { return this.view(); }
instead of this:
public actionresult index() { return this.file("index.html", "text/html"); }
here 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 find article useful.
bogdan
Comments
Post a Comment