How to do redirects in Gatsby

A step by step tutorial for redirecting web pages in GatsbyJS.

Oscar de la Hera Gomez
Written by Oscar de la Hera Gomez
First published on 09/14/2022 at 16:21
Last Updated on 09/16/2022 at 10:31
A flower that represents Gatsby, beneath it sits the text 'Redirects'.

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.

Download Open Source projectHow to create a Gatsby project that works with TypescriptHow to programmatically create pages using the GraphQL & Gatsby

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 git@github.com:delasign/typescript-serverless-starter.git
View Github Repository

Step One: Destructure createRedirects

A screenshot of VSCode showing you how the destructure the createRedirects prop within the actions available in the createPages function of the gatsby-node.js script.

Destructure the createRedirect prop from the actions available in the createPages function of the gatsby-node.js

Step Two: Create the redirect

A screenshot of VSCode showing you how to create a redirect within the createPages function of the gatsby-node.js script.

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 inquiries@delasign.com with any thoughts or feedback you may have.

SubscribeInquireView All PostsView All ServicesView All Work

Partner with us

We would love to get to know you and see how we can help your organization with its goals and needs.
Let's Talk

Stay Informed

Get occasional updates about our company, research, and product launches.
Subscribe