Skip to content

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

@phil-kt

Description

@phil-kt

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: #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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions