ASP.NET MVC with Angular :- page refresh or reload gives 404 error


Angular Ver : 5

I am working on a new project with ASP.NET MVC and have integrated angular 5 with it. The project is working fine except the page refresh yields the 404 page not found error. Whenever i hit refresh from the browser or reload the page, it gives the 404 error.

I have gone through many tutorials and discussions on this Angular page refresh problem, but no luck so far.

I am using the MVC shared view _Layout.cshtml to specify the angular lib references and the base reference as follows:-

  <!DOCTYPE html>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <base href="/">


    <script src="~/node_modules/core-js/client/shim.min.js"></script>
    <script src="~/node_modules/zone.js/dist/zone.js"></script>
    <script src="~/node_modules/systemjs/dist/system.src.js"></script>
    <script src="~/Web/systemjs.config.js"></script>
        System.import('Web/main.js').catch(function (err) { console.error(err); });

    @RenderSection("scripts", required: false)

Please suggest where should i make the changes.


In your RouteConfig located in App_Start change your route mapping to this

     name: "Default",
     url: "{*url}",
     defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }

Basically this will capture all your route paths.

Angular is a SPA environment, so you only need a single instance of a View which is your HomeController

Answered By – John Velasquez

Answer Checked By – Willingham (AngularFixing Volunteer)

Leave a Reply

Your email address will not be published.