Open juanpprieto opened 2 months ago
Yes, this is something we've solved several times with a form of fork of storefrontRedirect()
which feels tough.
I've added two params to our custom implementations to solve for this (localePrefix
and alsoMatchLocaleSpecificRedirects
which allows for concurrently searching for both locale specific and global redirects - eg: /path/
and /eu/path
when localePrefix === 'eu'
type StorefrontRedirect = {
/** The [Storefront client](/docs/api/hydrogen/2024-07/utilities/createstorefrontclient) instance */
storefront: Storefront<I18nBase>;
/** The [MDN Request](https://developer.mozilla.org/en-US/docs/Web/API/Request) object that was passed to the `server.ts` request handler. */
request: Request;
/** The [MDN Response](https://developer.mozilla.org/en-US/docs/Web/API/Response) object created by `handleRequest` */
response?: Response;
/** By default the `/admin` route is redirected to the Shopify Admin page for the current storefront. Disable this redirect by passing `true`. */
noAdminRedirect?: boolean;
/** By default, query parameters are not used to match redirects. Set this to `true` if you'd like redirects to be query parameter sensitive */
matchQueryParams?: boolean;
/** When present, storefrontRedirect will ignore this segment of the URL when searching for matching redirects */
localePrefix?: string;
/** By default, when localePrefix is set, it will not be used to search for matching redirects. Set this to `true` if you'd like to also search for redirects that are specific to a single locale */
alsoMatchLocaleSpecificRedirects?: boolean;
};
Context https://github.com/Shopify/hydrogen/discussions/2562#discussion-7228900