0

I am setting up angular routing for my asp.net mvc app, what I want is to redirect all the request for localhost/users/ to index page so that I can use angular's client side route except localhost/users/add, which I will use .Net's route. How to set it up RouteConfig?

Here is my current setting and I don't believe it's working

        routes.MapRoute(
            name: "UsersCatchAllRoute",
            url: "Users/{action}",
            defaults: new
            {
                controller = "Users",
                action = "Index",
                id = UrlParameter.Optional
            },
            constraints: new { action = @"(?-i)add" }

1 Answer 1

0

On our current project we use the following code. It means that anything in /app/ will be ignored and therefore handled by the angular routing. Hopefully even if this isn't exactly the code you need it will help you get there.

routes.IgnoreRoute("app/{*.}");

var default_route = new {
    controller = "Home",
    action = "Index",
    id = UrlParameter.Optional
};

routes.MapRoute(
    name: "Default",
    url: "{controller}/{action}/{id}",
    defaults: default_route
);

routes.MapRoute(
    name: "AngularApp",
    url: @"app/",
    defaults: default_route
);
Sign up to request clarification or add additional context in comments.

2 Comments

That's great, does that mean all your angular route start with /app/ ?
it does yes. This is ok for us. We will change it to / once we have recoded all of our MVC.net into Angular.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.