Angular 2 Routing Does Not Work When Deployed to Http Server

前端 未结 18 1912
误落风尘
误落风尘 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:00

    As per the documentation at https://angular.io/guide/deployment (Apache, you could also look for nginx) You need to point the server to index.html using the .htaccess file as

    RewriteEngine On
    # If an existing asset or directory is requested go to it as it is
    RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
    RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
    RewriteRule ^ - [L]
    # If the requested resource doesn't exist, use index.html
    

    RewriteRule ^ /index.html

提交回复
热议问题