mern-starter
mern-starter copied to clipboard
Disable server side rendering for a given route
Hi,
I try to set up a new react-leaflet component. When I try to access my route, I get an error :
ReferenceError: window is not defined at Object.
(.../leaflet/dist/leaflet-src.js:13043:3)
This error is totally fine because Leaflet needs access to the DOM to render properly.
Leaflet makes direct calls to the DOM when it is loaded, therefore this library is not compatible with server-side rendering. (here)
Is it possible to disable server side rendering for a given route ? What are the best practice to do so ?
Thank you :)
EDIT: I check before using my component if I'm on the browser or not. It works but I guess It's not a really nice way to do this... Any clues ?
if(process.title === 'browser'){
//render my component
}else {
return null
}
I have same problem too with components react-sound
and react-ionicons
.