I want to route the client after a form submit. I got it to work using reach's navigate() method, but I wonder if this is the Gatsby way?
I Googled but could not really find any details about programmatic routing in gatsby. What I do know is that it uses Reach router under the hood, and that Reach provides the navigate method which does exactly this.
So currently I import navigate:
import { navigate } from "@reach/router"
And then use it in my onSubmit code.
This works, and don't see any obvious side-effects, but I was wondering if there is perhaps a more Gatsby-specific way to handle this.
Given that the Gatsby documentation page on routing is a stub, I'd be happy to try and add this info, but only if it's the correct way of doing it. Hence this question.
Please check https://www.gatsbyjs.org/docs/gatsby-link/#programmatic-navigation
Gatsby does use @react/router navigate but it also does some extra stuff - like ensuring needed resources are loaded before changing page content
navigate() has issues with storybook. It fails with error message - _You may need an appropriate loader to handle this file type._
Am missing anything here?
Please suggest.
Thanks,
Most helpful comment
Please check https://www.gatsbyjs.org/docs/gatsby-link/#programmatic-navigation