New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Server-side files being redirected to using client routing due to registerServiceWorker #3608
Comments
Two things. First, you're not providing Second thing is that paths that don't start with a slash are always relative to the current document/route. So when you click on Because your whole site is hosted at the root, you can dispense with using |
@heyimalex Thanks for the clear explanation! EDIT: However, it didn't work. I used href='/path/to/pdf/', which in this case is just sitting in the public folder. However, after one click it continues to redirect to 404. So still the same issue. I think this is the best answer regarding mixing server and client routes: remix-run/react-router#3109 So it seems to be a react-routing issue, so will reclose this as it's not pertinent to react-scripts. |
Ok, here's the supposed solution for server routes: delete registerServiceWorker, it makes server routes and react-router not play nicely. However, this didn't work for me with my file. I'm going to reopen this then, as this part of create-react-app should not alter react-router's default behavior for server-side routes. I'm not quite sure what in registerServiceWorker is the cause. What I found through testing, is that when using a or an tag, the link would work fine in Firefox Private or Safari Private, only once in other browsers (Firefox, Chrome, Chrome Incognito). Perhaps something in handling the history causes them to fail and render the server route as a client route? EDIT: It looks like the service worker isn't caching the public files in setOfCachedUrls, could this be the problem? SECOND EDIT: After re-reading the Getting Started, I realize that server routes aren't supported, but would just like to state it would be nice if they could be, especially in the case of files in I will leave this for a maintainer to close just so they can note the feedback. Related issue: |
is it possible to prefix the path to your file with |
So for example in above case it should be |
I suggest to opt out of caching if it's causing you issues. cc @jeffposnick |
Fixed by #3419. |
@gaearon sweet! Is there any ETA on when the next release will be? Thanks! |
Within a week I'd say. |
@viankakrisna I think the '_' behavior is changed to '__' (double underline), am I right? |
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: #775Is this a bug report?
Yes
Environment
node -v
: 8.4.0npm -v
: 5.6.0react-scripts
: 1.0.11react-router
: 4.2.0react-router-dom
: 4.2.2Steps to Reproduce
{process.env.PUBLIC_URL + "path to file"}
Expected Behavior
Consistently open the file
Actual Behavior
Routed to 404 after using link once.
The text was updated successfully, but these errors were encountered: