如何告诉webpack dev服务器为任何路由提供index.html [英] How to tell webpack dev server to serve index.html for any route

查看:208
本文介绍了如何告诉webpack dev服务器为任何路由提供index.html的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

反应路由器允许反应应用程序处理 /任意/路由。为了这个工作,我需要我的服务器发送任何匹配的路线上的React应用程序。

React router allows react apps to handle /arbitrary/route. In order this to work, I need my server to send the React app on any matched route.

但是 webpack dev server 不处理任意的终点。

But webpack dev server doesn't handle arbitrary end points.

有一个这里使用附加快递服务
如何允许webpack-dev-server允许来自反应路由器的入口点

There is a solution here using additional express server. How to allow for webpack-dev-server to allow entry points from react-router

但是我不想启动另一个Express服务器来允许路线匹配。我只是想告诉webpack dev服务器匹配任何url,并发送我的反应应用程序。

But I don't want to fire up another express server to allow route matching. I just want to tell webpack dev server to match any url and send me my react app. please.

推荐答案

我发现最简单的解决方案包括一个小配置:

I found the easiest solution to include a small config:

  devServer: {
    port: 3000,
    historyApiFallback: {
      index: 'index.html'
    }
  }

我发现这是通过访问: http://jaketrent.com/post/pushstate-webpack-dev-server/

I found this by visiting: http://jaketrent.com/post/pushstate-webpack-dev-server/

这篇关于如何告诉webpack dev服务器为任何路由提供index.html的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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