简体   繁体   中英

React-snap and register service worker

I've been attempting to integrate react-snap with my create-react-app project. The issue I'm running into seems to stem from the registerServiceWorker() line in the index.js file.

The behaviors I'm observing is that when the registerServiceWorker() line is present, the app builds and I'm able to navigate normally, but the prerendered files are only filled with:

<html><head></head><body></body></html>

And the console is filled with:

 Failed to load resource: net::ERR_UNKNOWN_URL_SCHEME

When I comment out the registerServiceWorker() line in index.js react-snap runs with no errors and prerenders everything as it should, but I'm unable to navigate off of the '/' route. Attempting to go to any other route automtically re-routes me.

I have a feeling there is some adjustments I might need to make with the registerServiceWorker.js file that comes with create-react-app or option changes with react-snap.

I've been using version 1.21 of react-snap for reference.

Any ideas with direction on where to go with this would be wonderful.

registerServiceWorker , most likely, has nothing to do with your error, because react-snap by default uses HTTP (not HTTP S ) and serviceWorkers don't work over HTTP.

UPD : actually serviceWorker will work over HTTP for localhost. react-snap probably should disable serviceWorkers by default

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM