refreshing the page results in 404 error- Angular 6

后端 未结 10 1746
广开言路
广开言路 2020-12-05 06:54

I am building an application with the help of Angular6 and facing problems in routing. All the routes are working when I click on a particu

10条回答
  •  粉色の甜心
    2020-12-05 07:29

    Add .htaccess file to your src folder.

    .htaccess file

    
        RewriteEngine on
    
        # Don't rewrite files or directories
        RewriteCond %{REQUEST_FILENAME} -f [OR]
        RewriteCond %{REQUEST_FILENAME} -d
        RewriteRule ^ - [L]
    
        # Rewrite everything else to index.html
        # to allow html5 state links
        RewriteRule ^ index.html [L]
    
    

    Load .htaccess file in your build directory dist by adding it to assets in angular.json

    "assets": [
         "src/favicon.ico",
         "src/assets",
         "src/.htaccess"
    ],
    

提交回复
热议问题