1

I am creating an application in Asp.Net-MVC in VS2015. I want that application should support MVC routing and Angular 2 routing both.

I need MVC routing for Menu bar and Angular 2 routing for wizard present in each page lie below image.

Wizard

I have gone through various articles and finally used below code in my RouteConfig.cs file:

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

But this is not working properly. When i go from Home/Index to Home/Contact, it should not consider the angular 2 routing . But it is considering the angular 2 routing and showing the error :

Error: Cannot match any routes: 'Home/Contact'(…)

Below is screenshot:

Erros

How could i made the application compatible with both routings. Thanks

4
  • How do you redirect to this route? Click a url, type in the browser, etc.? Commented Nov 8, 2016 at 7:28
  • I have an anchor tag .. <a href = "/Home/Contact">Contact</a> on my index page...Page is redirecting to the Contact page but the console have an error when the contact page render.. Commented Nov 8, 2016 at 8:37
  • I think you need to use the full URL like http://..../Home/Contact Commented Nov 8, 2016 at 8:39
  • Alternatively check here: it's for Angular 1, but it might do the trick in Angular2 as well: stackoverflow.com/questions/16002984/…. The problem you have is that angular2 interprets the a tag and override it. You need to prevent angular from doing it. Commented Nov 8, 2016 at 8:40

1 Answer 1

2

There could be a workaround like already described in the answer to this question: How to use ASP.NET MVC and AngularJS routing?

So, in short, define a route that would catch urls intended for mvc controllers for sure, i.e. add a prefix

routes.MapRoute(
        name: "spa-fallback",
        url: "app/{*url}",
        defaults: new { controller = "Home", action = "Index" }
);
Sign up to request clarification or add additional context in comments.

Comments

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.