Angular 2 Routing Does Not Work When Deployed to Http Server

前端 未结 18 1857
误落风尘
误落风尘 2020-12-07 22:42

I am going to develop a simple Angular 2 application. I have created a project with routing, using Angular CLI and added several components to the app using \'ng generate co

18条回答
  •  醉梦人生
    2020-12-07 23:07

    The exact reason why this particular issue is being faced is because of your server settings.

    So when you implement the application there are certain steps that you will have to take. One of the essential steps is to mark a particular segment of your path say: http://domain-name/main where main being the path segment must be used as the identifier in your server settings say your server.js or app.js when it comes to a node backend or a webconfig file for IIS and Tomcat deployment.

    The reason for marking a particular segment is so that when the server receives any request with that particular segment + additional you reroute it to your application in www or public folder for the angular router to kick in.

    This process is known as url rewriting. Hence if the web server or the app server depending on the application size is not under your control then please use hashLocationStratergy else it is always neat to use pathLocationStartergy as it is helpful when it comes to history tracking and other aesthetic and performance benefits.

    To read more on this you can visit these links:

    For IIS: https://blog.angularindepth.com/deploy-an-angular-application-to-iis-60a0897742e7

提交回复
热议问题