Skip to content
This repository has been archived by the owner on Apr 11, 2024. It is now read-only.

Commit

Permalink
sync demo
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-phan committed Mar 1, 2024
1 parent 8f7f457 commit 871045a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 8 deletions.
17 changes: 9 additions & 8 deletions app/routes/($locale).$.tsx
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down
25 changes: 25 additions & 0 deletions app/routes/($locale).tsx
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit 871045a

Please sign in to comment.