How to do redirects in Gatsby

Oscar de la Hera Gomez
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.

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

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.

delasign logo

Book a Free Consultation.

An icon of an email.

Click here to email us.

Fill in the details below to book a free consultation or to let us know about something else. Whatever it is, we are here to help.

How can we help you ?

Contact Details