Is there a configuration in Github Pages that allows you to redirect everything to index.html for a Single Page App?

后端 未结 6 735
甜味超标
甜味超标 2021-01-17 15:28

I\'m trying to post my SPA app that works fine locally but when I push it to Github Pages, the interior pages don\'t register if you navigate to them directly.

For

6条回答
  •  伪装坚强ぢ
    2021-01-17 16:04

    If you are creating react app and you want to use Browser router in your gh pages the solution is to create 404.html file in your root directory and copy all the content in index.html to 404.html after you have build your react-app.

    When a user try accessing your page e.g https://successtar.github.io/teamwork/ GitHub will serve your index.html page while if a user try accessing https://successtar.github.io/teamwork/foo, since it does not exist, GitHub will serve the 404.html page which has same content as the index.html and with this you get your react app working as expected.

    Here is the source code for the example https://github.com/successtar/teamwork/tree/gh-pages

提交回复
热议问题