React-router urls don't work when refreshing or writing manually

前端 未结 30 2713
时光取名叫无心
时光取名叫无心 2020-11-21 05:07

I\'m using React-router and it works fine while I\'m clicking on link buttons, but when I refresh my webpage it does not load what I want.

For instance, I am in

30条回答
  •  悲哀的现实
    2020-11-21 05:47

    I found the solution for my SPA with react router (Apache). Just add in .htaccess

    
    
      RewriteEngine On
      RewriteBase /
      RewriteRule ^index\.html$ - [L]
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteCond %{REQUEST_FILENAME} !-l
      RewriteRule . /index.html [L]
    
    
    

    source: https://gist.github.com/alexsasharegan/173878f9d67055bfef63449fa7136042

提交回复
热议问题