AngularJS + ASP.NET MVC - Can you use both under "/"? -


i want serve angularjs spa "/" , reason have disabled default route , using

    // action not 'fire' due angular's routing...     routes.maproute(         name: "test",         url: "test",         defaults: new { controller = "home", action = "test" },         namespaces: new[] { "my.webapp.controllers" }     );      // index view has no layout , contains angular spa     routes.maproute(         name: "angularjs-spa",         url: "{*catchall}",         defaults: new { controller = "home", action = "index" },         namespaces: new[] { "my.webapp.controllers" }     ); 

i using following angular app config block

  .config(['$routeprovider', '$httpprovider', '$locationprovider', function ($routeprovider, $httpprovider, $locationprovider) {        $routeprovider.otherwise({ redirectto: '/404' });       $httpprovider.defaults.headers.common["x-requested-with"] = "xmlhttprequest";       $locationprovider.html5mode(true);   }]) 

my question can still somehow have regular server side page responds mvc action (in case /home/test)? issue seeing angular takes on routing , if define additional route (either before or after angular route), angular sees "otherwise" route...

few (undesirable) solutions

  • specify each angular app routes in mvc instead of {*catchall}
  • move angular spa non root action (e.g. /app)

you set $window.location directly otherwise:

myapp     .config(function($routeprovider, $locationprovider) {         $routeprovider             .when("/", {                 template: "<h1>welcome!</h1>"             })             .otherwise({                 template: " ",                 controller: function($location, $window) {                     $window.location.href = $location.path();                     return false;                 }             });         $locationprovider.html5mode(true);     }); 

Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -