简体   繁体   中英

Rendering Google Maps on Server Side

I have a npm package that exports a class for a google map (based on this article: http://cuneyt.aliustaoglu.biz/en/using-google-maps-in-react-without-custom-libraries/ ). When I import this package to a server-rendering react app, I get this error that window is not defined. I believe this is happening b/c window doesn't exist in node. However, I only reference window in componentDidMount lifecycle hook in the map pkg and I believe the server-side doesn't render that lifecycle hook.

What's the best way to render the map component on the server-side?

I had same question before. And found out the Google Map does not support rendering tiles on server side: https://github.com/google-map-react/google-map-react/issues/302#issuecomment-279984745

If you really want to render the map on server side for some special purposes. You can use headless browser to render and cache the result. Just like something the Prerender.io is doing.

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