diff --git a/app/routes/($locale).$.tsx b/app/routes/($locale).$.tsx index 566ca0c..eb95afd 100644 --- a/app/routes/($locale).$.tsx +++ b/app/routes/($locale).$.tsx @@ -1,16 +1,17 @@ -import {WeaverseContent} from '~/weaverse'; -import {type LoaderFunctionArgs} from '@shopify/remix-oxygen'; +import { WeaverseContent } from '~/weaverse'; +import { type LoaderFunctionArgs } from '@shopify/remix-oxygen'; -export async function loader({context}: LoaderFunctionArgs) { +export async function loader({ context }: LoaderFunctionArgs) { let weaverseData = await context.weaverse.loadPage({ type: 'CUSTOM', }); - if (!weaverseData) { - return new Response(null, {status: 404}); + + if (weaverseData?.page?.id && !weaverseData.page.id.includes('fallback')) { + return { + weaverseData, + }; } - return { - weaverseData, - }; + throw new Response(null, { status: 404 }); } export default function Component() { diff --git a/app/routes/($locale).tsx b/app/routes/($locale).tsx new file mode 100644 index 0000000..41e1297 --- /dev/null +++ b/app/routes/($locale).tsx @@ -0,0 +1,25 @@ +import type { LoaderFunctionArgs } from '@shopify/remix-oxygen'; + +export async function loader({ params, context }: LoaderFunctionArgs) { + const { language, country } = context.storefront.i18n; + + if ( + params.locale && + params.locale.toLowerCase() !== `${language}-${country}`.toLowerCase() + ) { + + let weaverseData = await context.weaverse.loadPage({ + type: 'CUSTOM', + }); + if (weaverseData?.page?.id && !weaverseData.page.id.includes('fallback')) { + return { + weaverseData, + }; + } + // If the locale URL param is defined, yet we still are still at the default locale + // then the the locale param must be invalid, send to the 404 page + throw new Response(null, { status: 404 }); + } + + return null; +}