Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I'm using AngularJS inside my ASP.NET MVC application, but I'm having a problem with nested routes. I'm using ASP.NET MVC routing but inside the SPA I'm using UI-Router.

My Home/Index is my AngularJS app and the <div ui-view> is in the Index.cshtml

I want my URL to be completely controlled by my AngularJS SPA (with html5Mode=true).

I have set up my RouteConfig in ASP.NET MVC like this:

routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

routes.MapRoute(
    name: "DefaultHome",
    url: "",
    defaults: new { controller = "Home", action = "Index" }
);

routes.MapRoute(
    name: "Default",
    url: "{.*}",
    defaults: new { controller = "Home", action = "Index" }
);

I'm using UI-Router, but that is irrelevant because this is a ASP.NET MVC routing problem. The AngularJS routing code however is the following:

app.config(function ($stateProvider, $urlRouterProvider, $locationProvider) {

    $urlRouterProvider.otherwise("/");

    $stateProvider
    .state('home', {
      url: "/",
      templateUrl: "Scripts/app/partials/home.html",
      controller: "HomeController"
    })
    .state('login', {
      url: "/login",
      templateUrl: "Scripts/app/partials/login.html",
      controller: "AccountController"
    })
    .state('login.list', {
      url: "/list",
      templateUrl: "Scripts/app/partials/login.list.html",
      controller: "AccountController"
    });

    $locationProvider.html5Mode(true);

});

This works perfect when I go to / or /login, but when I go to /login/list I get a 404 from my ASP.NET MVC application saying:

The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.

What is the problem? I have specified a {.*} rule so it should be directed to the AngularJS app.

share|improve this question
    
sounds more like a web.config issue since you want server to manage the virtual directories not your MVC framework –  charlietfl yesterday
    
What do you mean? I want everything to point to controller Home and action Index, so that my SPA works with nested routes. –  Gaui yesterday
    
which means you want the server to do that not your mvc framework –  charlietfl yesterday
    
Is it possible to let the MVC framework handle that? –  Gaui yesterday
    
why do you want a framework to do the job of the server? –  charlietfl yesterday

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.