Add canonical links to HTML pages Gatsby generates.
npm install gatsby-plugin-canonical-urlsAdd canonical links to HTML pages Gatsby generates.
This implementation is primarily helpful for distinguishing between https/http,
www/no-www but could possibly be extended to help with when sites add multiple
paths to the same page.
npm install gatsby-plugin-canonical-urls
``javascriptgatsby-plugin-canonical-urls
// In your gatsby-config.js
plugins: [
{
resolve: ,https://www.example.com
options: {
siteUrl: ,`
},
},
]
With the above configuration, the plugin will add to the head of every HTML page
a rel=canonical e.g.
`html`
URL search parameters are included in the canonical URL by default. If you worry about duplicate content because for example /blog and /blog?tag=foobar will be indexed separately, you should set the option stripQueryString to true. The latter will then be changed to /blog.
`js:title=gatsby-config.jsgatsby-plugin-canonical-urls
module.exports = {
plugins: [
{
resolve: ,https://www.example.com
options: {
siteUrl: ,``
stripQueryString: true,
},
},
],
}