Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to tell webpack dev server to serve index.html for any route

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.

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

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

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.

like image 634
eguneys Avatar asked Oct 12 '22 11:10

eguneys


People also ask

When we run the webpack-dev-server what port will it run on by default?

Expected Behavior. The port option should default to 8080 (just like the server does).

What is devServer?

A dev server is typically an internal web server used for testing and running code in development. It is a web server.


1 Answers

I found the easiest solution to include a small config:

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

I found this by visiting: PUSHSTATE WITH WEBPACK-DEV-SERVER.

like image 207
cmfolio Avatar answered Oct 17 '22 23:10

cmfolio