React-router v4 - cannot GET *url*

前端 未结 8 659
梦如初夏
梦如初夏 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:49

    Just to supplement Tyler's answer for anyone still struggling with this:

    Adding the devServer.historyApiFallback: true to my webpack config (without setting publicPath) fixed the 404/Cannot-GET errors I was seeing on refresh/back/forward, but only for a single level of nested route. In other words, "/" and "/topics" started working fine but anything beyond that (e.g. "/topics/whatever") still threw a 404 on refresh/etc.

    Just came across the accepted answer here: Unexpected token < error in react router component and it provided the last missing piece for me. Adding the leading / to the bundle script src in my index.html has solved the issue completely.

提交回复
热议问题