We optimize for Search engines by default by integrating a few key features:
We provde a canonicalize / useCanonical function that can be used to generate canonical URLs based on the current router and further configuration. This functionaliy is used by the PageMeta component as well as robots.txt and sitemap generation.
It considers the current locale, the domain.
We integrated JSON-LD for pages.
A
<JsonLd>
component provides Json-LD metadata for your pages. See
<ProductPageJsonLd/>
or
<BreadcrumbJsonLd>
for examples.
Page meta data is handled by the
import { PageMeta } from '@graphcommerce/next-ui'
component. Depending on the
page, the props that are passed are static or dynamic (functional page titles
are hardcoded).
// Example from /cart.tsx
<PageMeta
title={t`Cart (${data?.cart?.total_quantity ?? 0})`}
metaDescription={t`Cart Items`}
metaRobots={['noindex']}
// canonial={''}
/>
Dynamic example
// Example from /product/[url].tsx
<PageMeta
title={page?.metaTitle ?? title ?? ''}
metaDescription={page?.metaDescription ?? ''}
metaRobots={metaRobots}
canonical={`/${page?.url}`}
/>
Robots.txt and the sitemap files are generated on the fly and do not rely on any static generation.
Robots.txt is generated during runtime so that a separate robots.txt can be served for each domain that is configured.
GraphCommerce serves robots.txt & XML sitemap routes through the page router.
(pages/robots.txt.tsx
& pages/sitemap/
)
By default the robots.txt allows/disallows robots based on the
robotsAllow
configuration and contains a
separate sitemap for product, category & content pages.
When using a multi domain setup (e.g. https://mydomain.nl &
https://mydomain.com) configure the
domain
configuration in the storefront config.
/** @type {import('@graphcommerce/next-config/src/generated/config').GraphCommerceConfig} */
const config = {
// ...
storefront: [
{
locale: 'en',
magentoStoreCode: 'en_US',
defaultLocale: true,
domain: 'https://mydomain.com',
},
{
locale: 'nl',
magentoStoreCode: 'nl_NL',
defaultLocale: true,
domain: 'https://mydomain.nl',
},
// ...
],
}
canonicalBaseUrl
configuration, the
robots.txt will only include sitemaps specific to that domain.
When using a multi locale based setup (e.g. https://graphcommerce.vercel.app/en-gb), the robots.txt will include sitemaps for all locales the configured domain. Example: robots.txt
GraphCommerce generates sitemaps per locale for sitemap/product.xml, sitemap/category.xml and sitemap/content.xml.
Limitations: We currently do not support hreflang in sitemaps since there is no Magento GraphQL API to get the hreflang for a page.