Skip to main content

Route templates

The createShopifyRouteTemplates function tells Hydrogen where your app serves products, collections, and other Shopify resources. Use the function when your app serves a resource at a path other than Shopify's default.

Import createShopifyRouteTemplates from @shopify/hydrogen.

Pass the same route templates to handleShopifyRoutes, handleShopifyRedirects, ShopifyScripts, and the search result URL functions.


Tells Hydrogen where your app serves products, collections, and other Shopify resources. Pass the returned object to handleShopifyRoutes, handleShopifyRedirects, the ShopifyScripts routes option, and the predictive search URL helpers.

Add a key only for a route that your app serves at a non-standard path. Hydrogen uses Shopify's default path for each key that you leave out. Pass an empty object when your app serves every route at its default path. Each template starts with / and includes the handle placeholders for its route. Leave the locale path prefix out of templates. Hydrogen adds the prefix for you.

TypeScript checks the shape of each template. The function returns the object that you pass.

Anchor to routes
routes
TRoutes extends
required

The non-standard paths that your app serves, keyed by standard route name.

const TRoutes extends

The route templates, typed for Hydrogen's route, redirect, and URL helpers.

Examples

TypeScript

import { createShopifyRouteTemplates } from "@shopify/hydrogen";

export const routeTemplates = createShopifyRouteTemplates({
product: "/p/:productHandle",
collection: "/c/:collectionHandle",
article: "/journal/:blogHandle/:articleHandle",
cart: "/basket",
policy: "/legal/:policyHandle",
search: "/find",
});

Was this page helpful?