React-router v4 - cannot GET *url*

前端 未结 8 664
梦如初夏
梦如初夏 2020-12-07 14:04

I started to use react-router v4. I have a simple in my app.js with some navigation links (see code below). If I navigate to localhost/voca

8条回答
  •  不知归路
    2020-12-07 14:38

    I was having the same issue, what fixed it for me was editing my package.json file, and under scripts: {

    "build": "webpack -d && copy src\\index.html dist\\index.html /y && webpack-dev-server --content-base src --inline --port 3000"
    

    at the end of my webpack build code I added --history-api-fallback this also seemed like the easiest solution to the Cannot GET /url error

    Note: the next time you build after adding --history-api-fallback you will notice a line in the output that looks like this (with whatever your index file is):

    404s will fallback to /index.html

提交回复
热议问题