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 trying to remove # from angularjs default routing from an asp.net MVC project using html5

app.js

  .config(function ($routeProvider, $locationProvider) {
        $locationProvider.hashPrefix("!").html5Mode(true);

        $routeProvider
         .when('/', { templateUrl: '/home/index' })
         .when('/domain', { templateUrl: '/domain/index' })                        
         .otherwise({ redirectTo: '/' });

My landing point is /Home/Spa

.net MVC routing:

routes.MapLocalizedRoute("HomePage",
                   "",
                   new { controller = "Home", action = "Spa" },
                   new[] { "Nop.Web.Controllers" });

     routes.MapLocalizedRoute("Default2",
      "{*url}",
      new { controller = "Home", action = "Spa" },
      new[] { "Nop.Web.Controllers" });

      routes.MapRoute(
            "Default", // Route name
            "{controller}/{action}/{id}", // URL with parameters
            new { controller = "Home", action = "Index", id = UrlParameter.Optional },
            new[] { "Nop.Web.Controllers" }
        );
     routes.MapRoute("ShoppingCart",
                        "cart/",
                        new { controller = "ShoppingCart", action = "Cart" },
                        new[] { "Nop.Web.Controllers" });

Everything works fine but sometimes i want to use Non Spa routing like ShoppingCart (/cart), it always redirect back to Home due to .otherwise({ redirectTo: '/' });.

How can i make some exception rule in this case ?

share|improve this question
    
what does it do if you remove the otherwise part? –  MajoB Sep 30 at 15:29
    
it shows nothing in ngView –  nam vo Sep 30 at 15:31
    
you can try to watch for a route change $scope.$on('$locationChangeStart', function(event, next) {), check the next route and apply window.location.href = next if it is a mvc route. –  MajoB Sep 30 at 15:34

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.