Serve: react-router applications getting 404 error with version 10.1.2

Created on 7 Feb 2019  路  19Comments  路  Source: vercel/serve

Create a CRA application with react-router. Works fine with webpack development server, but production builds all get a 404 error with non-root urls running [email protected] Running [email protected] works fine. Not sure what changed in the new version, but it seems to have broken SPA applications routing.

Most helpful comment

I'm running [email protected] and it's working fine for me with the react-router-dom BrowserRouter in the production build.

And I also just use the single mode:

serve -s .

Thans so much! it works in V 11.2.0

All 19 comments

Same problem.
I think the cause is this commit

Same issue here. All good before 10.1.2, now I get a 404 on all routes.

Yeah, single mode is broken now.

Can't seem to reproduce this issue. Version of create-react-app is 2.1.5, react-router-dom ^4.3.1, serve 10.1.2.

Here a project I tested on: https://github.com/tryzniak/my-react-app

Likely same root cause for me, but getting 404's when using re-writes but not when hitting a resource directly.

serve.json

{
  "public": "dist",
  "rewrites": [
    {
      "source": "/app/:project/manifest.json",
      "destination": "/:project/manifest.json"
    }
  ]
}

In my dist folder I simply have a file /dist/web/manifest.json

When navigating to http://localhost:5000/app/web/manifest.json I receive a 404
When navigating to http://localhost:5000/web/manifest.json I receive the file.

same here, but 10.1.1 works fine

@AndyBitz could you fix the problem?

Version 10.1.2. I am also getting 404 when I manually type a url.

I also confirm that 10.1.1 works fine.

same issue with 10.1.2 (certainly caused by https://github.com/zeit/serve-handler/commit/c212e2d431d4331f11ed49fe8e450b50181a4415).

Issue is still there in 11.0.0.

Any update on this issue?

I'm running [email protected] and it's working fine for me with the react-router-dom BrowserRouter in the production build.

And I also just use the single mode:

serve -s .

Can confirm this behaviour:

rewrites: [
  { 'source': '**', 'destination': '/index.html' }
]

... gives me a 404 in version 11.0.0. In version 10.1.1 not.

Four months with this issue...
Now the version 10.1.1 has this vulnerability...

A fix for this was released today. Can you confirm?

@leo fixed for me in version 11.0.2. Thanks!

@leo I confirm it is working in version 11.0.2. Thanks!

馃憤

I'm running [email protected] and it's working fine for me with the react-router-dom BrowserRouter in the production build.

And I also just use the single mode:

serve -s .

Thans so much! it works in V 11.2.0

I'm getting 404 when refreshing a react app using react-router. Running with -s flag, v11.3.2
Am I missing something?

Was this page helpful?
0 / 5 - 0 ratings