简体   繁体   English

反应快照并注册服务人员

[英]React-snap and register service worker

I've been attempting to integrate react-snap with my create-react-app project. 我一直在尝试将react-snap与我的create-react-app项目集成在一起。 The issue I'm running into seems to stem from the registerServiceWorker() line in the index.js file. 我遇到的问题似乎源于index.js文件中的registerServiceWorker()行。

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: 我观察到的行为是,当registerServiceWorker()行存在时,该应用会生成并且我能够正常导航,但是预渲染的文件仅填充有:

<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. 当我注释掉index.js中的registerServiceWorker()行时,react-snap运行没有错误,并预渲染了所有内容,但是我无法导航到“ /”路线之外。 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. 我感觉可能需要对create-react-app附带的registerServiceWorker.js文件或带有react-snap的选项进行一些调整。

I've been using version 1.21 of react-snap for reference. 我一直在使用1.21版的react-snap作为参考。

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. registerServiceWorker很可能与您的错误无关,因为默认情况下react-snap使用HTTP(不是HTTP S ),而serviceWorkers不能通过HTTP进行工作。

UPD : actually serviceWorker will work over HTTP for localhost. UPD :实际上,serviceWorker将通过HTTP为本地主机工作。 react-snap probably should disable serviceWorkers by default 默认情况下,react-snap可能应禁用serviceWorkers

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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