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

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -