Gatsby: Programmatic routing: Should I use Reach router's navigate() method, or is there a Gatsby-specific way?

Created on 23 Oct 2018  路  3Comments  路  Source: gatsbyjs/gatsby

Summary

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?

Relevant information

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.

question or discussion

Most helpful comment

All 3 comments

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,

Was this page helpful?
0 / 5 - 0 ratings

Related issues

3CordGuy picture 3CordGuy  路  3Comments

benstr picture benstr  路  3Comments

andykais picture andykais  路  3Comments

ghost picture ghost  路  3Comments

signalwerk picture signalwerk  路  3Comments