webpack-dev-server react-router 推送状态 [英] webpack-dev-server react-router push state

查看:35
本文介绍了webpack-dev-server react-router 推送状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试让 react-router 与 webpack-dev-server 一起工作,但一直无法获取/SOMEURL.这是因为 webpack-dev-server 正在寻找该特定文件但找不到它.我希望 webpack 使用 react-router 而不是搜索文件本身.

I am trying to get react-router to work with webpack-dev-server but keep getting cannot Get /SOMEURL. This is because webpack-dev-server is looking for that specific file but cannot find it. I'd like webpack to resort to using react-router vs searching for the files itself.

我该如何设置?

我的咕哝:

'webpack-dev-server': {
      options: {
        hot: true,
        port: 8000,
        webpack: webpackDevConfig,
        publicPath: '/assets/',
        contentBase: './<%= pkg.src %>/'
      },

      start: {
        keepAlive: true,
      }
    },

推荐答案

使用 --history-api-fallback 选项到 webpack-dev-server.这使用 connect-history-api-fallback 来提供 index.html如果路由与任何其他文件不匹配.(这意味着您必须使用 index.html 作为 HTML 页面的文件名.)

Use the --history-api-fallback option to webpack-dev-server. This uses connect-history-api-fallback to serve up index.html if the route doesn't match any other files. (This does mean you have to use index.html as the filename for your HTML page.)

这篇关于webpack-dev-server react-router 推送状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆