How to do redirects in Gatsby
A step by step tutorial for redirecting web pages in GatsbyJS.
The following tutorial builds of our Open Source starter project and walks you through how to redirect web pages using the Gatsby Node script.
We recommend downloading our Open Source project, checking out the tutorial/frontend-fragments branch and carrying out the steps outlined below. All relevant changes can be found on the tutorial/redirects branch.
git clone email@example.com:delasign/typescript-serverless-starter.git
Step One: Destructure createRedirects
Destructure the createRedirect prop from the actions available in the createPages function of the gatsby-node.js
Step Two: Create the redirect
Within the createPages Gatsby node function, create your redirect. Sample code showing you how to redirect fromPath to the landing page is available below.
Any Questions ?
We are actively looking for feedback on how to improve this resource. Please send us a note to firstname.lastname@example.org with any thoughts or feedback you may have.