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

前端 未结 5 858
灰色年华
灰色年华 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:58

    To extend Jildert's answer, I did the same - copied index.html to 404.html before deploying to the github pages and it worked.

    So I've just updated pre-deploy section of package.json to include this copy action and now it works fine with BrowserRouter:

    "predeploy": "npm run build && cp build/index.html build/404.html",
    "deploy": "gh-pages -d build"
    

提交回复
热议问题