diff --git a/packages/hydrogen-remix/routing/redirect.ts b/packages/hydrogen-remix/routing/redirect.ts index b49fa4558d..90f08e235a 100644 --- a/packages/hydrogen-remix/routing/redirect.ts +++ b/packages/hydrogen-remix/routing/redirect.ts @@ -3,7 +3,7 @@ import {HydrogenContext} from '..'; export async function notFoundMaybeRedirect( request: Request, context: HydrogenContext, -): Promise { +): Promise { const {pathname, search} = new URL(request.url); const {urlRedirects} = await context.storefront.query<{ urlRedirects: { @@ -17,14 +17,14 @@ export async function notFoundMaybeRedirect( }); if (urlRedirects?.edges?.length) { - throw new Response(null, { + return new Response(null, { status: 301, headers: { location: urlRedirects.edges[0]?.node?.target!, }, }); } else { - throw new Response('Not found', {status: 404}); + return new Response('Not found', {status: 404}); } } diff --git a/templates/demo-store/app/components/SortFilter.tsx b/templates/demo-store/app/components/SortFilter.tsx index 8959c6091f..c5cb188210 100644 --- a/templates/demo-store/app/components/SortFilter.tsx +++ b/templates/demo-store/app/components/SortFilter.tsx @@ -1,4 +1,4 @@ -import {useState} from 'react'; +import React, {useState} from 'react'; import {Heading, Button, Drawer as DrawerComponent} from '~/components'; import {Link, useLocation} from '@remix-run/react'; import type { diff --git a/templates/demo-store/app/routes/collections/$collectionHandle.tsx b/templates/demo-store/app/routes/collections/$collectionHandle.tsx index 8038f30b90..18ed72a1c3 100644 --- a/templates/demo-store/app/routes/collections/$collectionHandle.tsx +++ b/templates/demo-store/app/routes/collections/$collectionHandle.tsx @@ -60,7 +60,7 @@ export async function loader({params, request, context}: LoaderArgs) { }); if (!collection) { - await notFoundMaybeRedirect(request, context); + throw await notFoundMaybeRedirect(request, context); } return json({collection}); diff --git a/templates/demo-store/app/routes/index.tsx b/templates/demo-store/app/routes/index.tsx index 1cece848c8..82649de745 100644 --- a/templates/demo-store/app/routes/index.tsx +++ b/templates/demo-store/app/routes/index.tsx @@ -52,7 +52,7 @@ export async function loader({request, params, context}: LoaderArgs) { ) { // If the lang URL param is defined, yet we still are on `EN-US` // the the lang param must be invalid, send to the 404 page - await notFoundMaybeRedirect(request, context); + throw await notFoundMaybeRedirect(request, context); } const {shop, hero} = await context.storefront.query<{ diff --git a/templates/demo-store/app/routes/journal/$journalHandle.tsx b/templates/demo-store/app/routes/journal/$journalHandle.tsx index 1dcc29ac1e..b52dcbc6c6 100644 --- a/templates/demo-store/app/routes/journal/$journalHandle.tsx +++ b/templates/demo-store/app/routes/journal/$journalHandle.tsx @@ -45,7 +45,7 @@ export async function loader({request, params, context}: LoaderArgs) { }); if (!blog?.articleByHandle) { - await notFoundMaybeRedirect(request, context); + throw await notFoundMaybeRedirect(request, context); } const article = blog.articleByHandle; diff --git a/templates/demo-store/app/routes/pages/$pageHandle.tsx b/templates/demo-store/app/routes/pages/$pageHandle.tsx index ad89eb1e02..4362bd7a06 100644 --- a/templates/demo-store/app/routes/pages/$pageHandle.tsx +++ b/templates/demo-store/app/routes/pages/$pageHandle.tsx @@ -24,7 +24,7 @@ export async function loader({request, params, context}: LoaderArgs) { }); if (!page) { - await notFoundMaybeRedirect(request, context); + throw await notFoundMaybeRedirect(request, context); } return json( diff --git a/templates/demo-store/app/routes/policies/$policyHandle.tsx b/templates/demo-store/app/routes/policies/$policyHandle.tsx index 672f7cb061..337f7be6c0 100644 --- a/templates/demo-store/app/routes/policies/$policyHandle.tsx +++ b/templates/demo-store/app/routes/policies/$policyHandle.tsx @@ -38,7 +38,7 @@ export async function loader({request, params, context}: LoaderArgs) { const policy = data.shop?.[policyName]; if (!policy) { - await notFoundMaybeRedirect(request, context); + throw await notFoundMaybeRedirect(request, context); } return json( diff --git a/templates/demo-store/app/routes/products/$productHandle.tsx b/templates/demo-store/app/routes/products/$productHandle.tsx index 6cb2eabe23..4c432f8bbe 100644 --- a/templates/demo-store/app/routes/products/$productHandle.tsx +++ b/templates/demo-store/app/routes/products/$productHandle.tsx @@ -72,7 +72,7 @@ export const loader = async ({params, request, context}: LoaderArgs) => { }); if (!product) { - await notFoundMaybeRedirect(request, context); + throw await notFoundMaybeRedirect(request, context); } return defer({