Seo
The Seo
component renders SEO information on a webpage. You can customize this component using passthrough props.
Example code
import {Seo, useShopQuery, useRouteParams, gql} from '@shopify/hydrogen';
const QUERY = gql`
query PageDetails($handle: String!) {
page(handle: $handle) {
title
body
seo {
title
description
}
}
}
`;
export default function Page() {
const {handle} = useRouteParams();
const {data} = useShopQuery({query: QUERY, variables: {handle}});
if (!data.pageByHandle) {
return <NotFound />;
}
const page = data.pageByHandle;
return <Seo type="page" data={page} />;
}
Props
The Seo
component has two props: type
and data
. The type
prop accepts defaultSeo
, homepage
, product
, collection
, page
, or noindex
. Each type
expects a different data
shape.
Type | Data | Description |
---|---|---|
defaultSeo | Omit&.md#60;DefaultPageType, 'url'> Data shape:
| The SEO information to render as default on every page of the website. This includes the defaults for title, description, and title template. The title template defaults to the pattern of %s - ${data.title} , where %s is the title of children components. You can overwrite this pattern using the data.titleTemplate prop. The language defaults to the locale within the ShopifyProvider component. |
homepage | Omit<HomePageType, 'url'> | The SEO information to render on the home page of the website. Corresponds to the Storefront API's Seo object. |
product | Omit<ComponentProps<typeof ProductSeo>, 'url'> | The SEO information to render on the product page. Corresponds to the Storefront API's Product object. |
collection | Omit<ComponentProps<typeof CollectionSeo>, 'url'> | The SEO information to render on the collection page. Corresponds to the Storefront API's Collection object. |
page | Omit<ComponentProps<typeof PageSeo>, 'url'> | The SEO information to render on pages (for example, "About" or "Shipping"). Corresponds to the Storefront API's Page object. |
noindex | Omit<ComponentProps<typeof NoIndexPageSeo>, 'url'> Data shape:
| Instructs bots to not index a page (for example, an authenticated account management page). |
Component type
The Seo
component is a shared component, which means that it renders on both the server and the client. For more information about component types, refer to React Server Components.