Jeremy Miller Jeremy Miller - 1 year ago 76
AngularJS Question

Angular Routing with MVC Routing mixed -Refresh page throws

I am essentially putting together an mvc 5 / angular 1.5 application that is a hybrid.

It is using both routing engines, and I have seen this done before and I even have the codebase of an example of one mvc/angular app but that one refresh is fine.

Now with the AdminController If I'm on the index razor page and I refresh this page, it is still just fine

However, I have menu links at the top of the page and it navigates based on clicking on link as defined in _Layout.cshtml


I click on "Customers" and It routes to show the correct text and buttons on the page, but the URL is now showing

well, there is no customer controller so that must not be correct.

If I refresh the page , I get a 404

I suppose that I know that it makes sense that it is not showing a correct URL to route to, but I am not sure why the angular and html and all its glory was showing up to begin with.

Answer Source

Assuming that your Angular routing is "ok" I assume it is as you are saying that it displays html and angular etc..

So mvc routing then NEEDS to be modded.

I'm guessing you did NOT add anything to your RouteConfig

You are saying that you have AdminController thus /Admin and then you have customer so maybe this is what will work for you

Put this after the ignoreroute and before a default route. Slap in right in the middle , and add in more as you create more mvc razor routing pages as needed

           name: "customer",
           url: "customer/{*catch-all}",
           defaults: new
               controller = "Admin",
               action = "Customer"

catch-all will help you , example of explaining it is here

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download