0

What we have is an Asp.Net MVC site that we want to transition to an AngularJS-WebAPI site. That means we will have both .html and .cshtml pages in the same project. I solved the problem of sharing the OAuth tokens. I can also navigate around most of the menu choices. That means I can move around the angular pages and I can move around the mvc pages. I can also move from the angular pages to the mvc pages. The problem manifests itself when I try to navigate from mvc pages back to the angular ones. Once the server side routing takes over from the client routing it won't let get.

I've spent the past couple of days trying all sorts of ideas that I gleaned from StackOverflow and various blogs with no luck. Most of the advice is about how to host Angular inside MVC pages and that is not what I am looking for. I've tried telling MVC routing to "IgnoreRoute"s as well as tried to tell it to funnel all angular routes through a dedicated MVC controller. There were multiple responses on SO that involved complex programming in Angular that I had a hard time understanding and eventually rejected because I don't believe Angular should be that difficult. I only found one comment on a posting that said you should not even bother to try mixing the two paradigms.

Does anyone have a solution to mixing an Angular SPA page with MVC pages? How can I get MVC to route back to my Angular SPA page?

8
  • 1
    No simple answer on how you need to code this or set up web.config but the angular routing basics are fairly simple. You always have to deliver the app entry point from server and let angular manage any paths in url beyond the entry point. Commented Jan 24, 2016 at 20:34
  • Why do you need the MVC pages? Wouldn't be cleaner to simply have angular as the UI (with just one html page) and the controllers as the backend? If this was the case, simply move the controllers to a sub-folder (api/) and then, in IIS Management, convert this folder into an application. Commented Jan 25, 2016 at 2:30
  • 1
    can you elaborate a bit more around your actual issue the client routing it won't let get is for me a bit vague. Having said that, I've accomplished this using some url rewriting. This does mean that all your mvc routes need to be separate from your angular ones. Commented Jan 25, 2016 at 7:13
  • @Skaparate The MVC pages already exist. There are 30-50 pages that would need to be converted. We have made the commitment to get off MVC and into a pure web front end that uses WebAPI on the back end (web page server and web services server as two different servers). My intent is to convert the pages to Angular one at a time which would have both Angular pages and MVC pages in the same project with the MVC pages disappearing as I went along. This is much better for testing gradually. At least, that is the hope. Commented Jan 25, 2016 at 23:39
  • 1
    Is your SPA reloading when You navigate from Razor? Are there any errors in the web browser console? You could check if the pages are being transferred correctly from the server (maybe the routes are not right when transitioning from razor?) Commented Jan 26, 2016 at 0:06

0

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.