I have been trawling through React specific posts on trying to fix the issue where refreshing a page breaks the routing. However, I am struggling to apply any fixes to the my Meteor React app. It seems like such a common thing that requires fixing, I assume every Meteor React app developer would have to overcome it.
Here are my routes set up in my client side app.jsx:
However, if I refresh this page, or navigate to it directly, the page breaks as the useParams() returns null.
There are various React specific topics on this recommended using Browser History and setting up routes both on the client and server side. However, I am struggling trying to implement the solutions in the context of a Meteor app.
Ok, so, it seems that useParams() is actually always returning the value, however, the GodsCollection becomes null whenever I refresh the page. If I actually navigate to the page from navigation, it works.
I don’t use MiniMongo – I’m using Apollo – but is there a Meteor or MiniMongo Chrome plug-in you can use to get visibility into what’s going on with the MiniMongo cache?
Maybe you have other pages which subscribes to ‘gods’ collection already.
The god variable returned by useTracker could be null at first. Because the subscription needs time to finish. So your component should check if it’s ready or not.
If you tried to access the god.name immediately, it could lead to error. You can check if god available or try to use god?.name instead.