question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Server-side files being redirected to using client routing due to registerServiceWorker

See original GitHub issue

There’s this odd bug I’m encountering where using process.env.PUBLIC_URL to link to pdf’s in the public folder doesn’t work consistently with react-router. It will work fine on localhost, but the moment I deploy it live, the link to the pdf works only once or twice before failing and going to a 404 page.

Also not sure if this bug lies here or with react-router, I couldn’t find any reference on their repo. Sorry if it’s the wrong spot.

Has anyone else encountered this? For now I’m serving the pdf from within src, but really dislike the complicated path and hash produced by file-loader, so might have to end up ejecting…

I’d also like to note this worked in prior versions of create-react-app as seen here: https://github.com/facebookincubator/create-react-app/issues/775

Is this a bug report?

Yes

Environment

  1. node -v: 8.4.0
  2. npm -v: 5.6.0
  3. react-scripts: 1.0.11
  4. react-router: 4.2.0
  5. react-router-dom: 4.2.2

Steps to Reproduce

  1. Add file to public
  2. Reference it in code using {process.env.PUBLIC_URL + "path to file"}
  3. Create a build and deploy
  4. Click link several times, notice that it stops working

Expected Behavior

Consistently open the file

Actual Behavior

Routed to 404 after using link once.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:11 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
gaearoncommented, Jan 11, 2018

Within a week I’d say.

1reaction
LinkCablecommented, Dec 22, 2017
Read more comments on GitHub >

github_iconTop Results From Across the Web

React-router URLs don't work when refreshing or writing ...
Basically you define a route for /* and make it respond with your HTML page. The tricky thing here is to make sure...
Read more >
Client-Side and Server-Side Redirects in Next.js
Client -side, we can use next/router. But that doesn't exist on the server. * So on the server we must do an HTTP...
Read more >
Tutorial - Universal App with React Router - Zac Fukuda
We are going to create simple static-page website, covering how to redirect or show the 404 page, and how to render the component...
Read more >
Deploy React and Express to Heroku - Dave Ceddia
A step-by-step tutorial where you'll make a React app, an Express API server, and deploy both to Heroku.
Read more >
math3d-component - npm
Static Server; Other Solutions; Serving Apps with Client-Side Routing; Building for Relative Paths; Azure; Firebase; GitHub Pages; Heroku ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found