React-router v4 - cannot GET *url*

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

    If you use Webpack check your configuration in part of server configuration for the "contentBase" attribute. You can set by this example:

    devServer: {
        ...
        contentBase: path.join(__dirname, '../')
        ...
    }
    
    0 讨论(0)
  • 2020-12-07 15:05

    If you are using Express (not Webpack), this worked for me..

    app.get('/*', function(req, res) {
      res.sendFile(path.join(__dirname, 'path/to/your/index.html'), function(err) {
        if (err) {
          res.status(500).send(err)
        }
      })
    })
    
    0 讨论(0)
提交回复
热议问题