Can I create routes with react-router for a github-pages site?

前端 未结 5 846
灰色年华
灰色年华 2020-12-03 20:01

Ok, so I\'ve made a SPA using React and React-Router and have pushed it to github pages, but none of the routes I have written work when I refresh or click back in my browse

5条回答
  •  情深已故
    2020-12-03 20:47

    Aside from using hashHistory as suggested in the accepted answer, there is another workaround. Look here.

    Basically, you create a spoof 404.html file which has a script that converts the requested path into the query string & redirects the browser to the index page with the query string attached to the URL. After the index file is loaded, the original path is restored from the query string & ReactRouter picks up the changes.

    A neat solution, but not production-ready, either.

提交回复
热议问题