Skip to content

Commit

Permalink
Fix the <Seo /> component to render canonical URLs without trailing s…
Browse files Browse the repository at this point in the history
…lashes (#1622)
  • Loading branch information
blittle authored Jan 9, 2024
1 parent eb0f4bc commit 36d6fa2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
7 changes: 7 additions & 0 deletions .changeset/polite-singers-joke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@shopify/hydrogen': patch
---

Fix the `<Seo />` component to render canonical URLs without trailing slashes. For example, both https://hydrogen.shop/collections/freestyle/ and https://hydrogen.shop/collections/freestyle return a canonical link of https://hydrogen.shop/collections/freestyle.

Thank you @joshuafredrickson for reporting.
5 changes: 3 additions & 2 deletions packages/hydrogen/src/seo/generate-seo-tags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -411,15 +411,16 @@ export function generateSeoTags<
}

const urlWithoutParams = content.split('?')[0];
const urlWithoutTrailingSlash = urlWithoutParams.replace(/\/$/, '');

tagResults.push(
generateTag('link', {
rel: 'canonical',
href: urlWithoutParams,
href: urlWithoutTrailingSlash,
}),
generateTag('meta', {
property: 'og:url',
content: urlWithoutParams,
content: urlWithoutTrailingSlash,
}),
);

Expand Down

0 comments on commit 36d6fa2

Please sign in to comment.