Include Redirect component in Gatsby-Link #26046
Replies: 4 comments
-
I definitely see the benefit of re-exporting Redirect from gatsby. Especially since we export Link too. Would you be wiling to submit a PR for this? |
Beta Was this translation helpful? Give feedback.
-
Yeah, I can do that! I'll update the docs as well. |
Beta Was this translation helpful? Give feedback.
-
I imported Redirect from reach in gatsby-link/src/index.js which compiles and adds it to index.js in the root of gatsby-link. Seems to be working as I can
I'm having trouble exporting from gatsby though. I'm assuming I want to import from gatsby-link and export again from the gatsby-package. It looks like that is being done for the other components/methods in gatsby-link in gatsby/cache-dir/gatsby-browser-entry, but when I try to import and export there, I can't I'm running |
Beta Was this translation helpful? Give feedback.
-
@connorlindsey you should indeed export it from gatsby-link and then export it from gatsby. If you have a PR we can go from there. |
Beta Was this translation helpful? Give feedback.
-
Summary
When navigating programmatically, Gatsby provides the navigate function which causes build errors when used in the render method (Window is not defined. See issue #10421). The build error message is not very helpful in tracking this mistake down and the documentation doesn't mention this. I was lucky to find a few issues mentioning this and was able to put navigate in a useEffect. There are a couple things I think to improve this:
Basic example
Motivation
Redirecting programmatically is common, for example when creating components that redirect if a user isn't logged in.
Beta Was this translation helpful? Give feedback.
All reactions