How to fix "//*" canonical error in GatsbyJS

Oscar de la Hera Gomez
A flower that represents Gatsby with the text "Fix "//*" canonical error" beneath it.

Gatsby creates a "/*" canonical URL when using the "path" from a programmatically created page. Use the page URI to remove this error.

A screenshot of Chrome showing how the canonical url of a page has a "//*" in it.

The following article addresses the issue above by which Gatsby creates pages with a "/*" in the canonical URL instead of the correct URI.

A screenshot of VSCode highlighting the path that is passed into a programatically created page in Gatsby. Highlighted is also how we use it to generate the SEO for the page, through the react helmet NPM package.

This occurs when an individual programmatically create pages using the "gatsby-node." script and subsequently uses the "path" that is produced by the "gatsby-node" script to create the canonical URL.

To avoid it follow the steps outlined below.

Step One: Remove the Path

A screenshot of VSCode highlighting how we removed the "path" from the props of a page that was created programmatically using the gatsby-node script.

In all the templates that use the path, remove the path from the props.

Step Two: Add the URI to the GraphQL Query

A screenshot of VSCode highlighting how we added a URI to a GraphQL query.

Add the uri to the GraphQL query and associated typescript types.

Step Three: Update the Canonical URL

A screenshot of VSCode showing how we pass the URI to the metadata of a page.

Wherever you had previously used the path, use the uri.

Please note this might require you updating the logic.

Step Four: Test

A screenshot of Chrome highlighting that the canonical url has been fixed.

Build, deploy the website and confirm the canonical error has been resolved.

Looking to learn more about ReactJS, GatsbyJS or SEO ?

Search our blog to find educational content on learning SEO as well as how to use ReactJS and GatsbyJS.

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