import { getTranslations } from 'next-intl/server'; import { Container, Button, Heading } from '@/components/ui'; import Scribble from '@/components/Scribble'; import { getPayload } from 'payload'; import configPromise from '@payload-config'; import { headers } from 'next/headers'; import ClientNotFoundTracker from '@/components/analytics/ClientNotFoundTracker'; export default async function NotFound() { const t = await getTranslations('Error.notFound'); // Try to determine the requested path const headersList = await headers(); const urlPath = headersList.get('x-invoke-path') || ''; let suggestedUrl = null; let suggestedLang = null; // If we have a path, try to see if the last segment (slug) exists in ANY locale if (urlPath) { const slug = urlPath.split('/').filter(Boolean).pop(); if (slug) { try { const payload = await getPayload({ config: configPromise }); // Check posts const postRes = await payload.find({ collection: 'posts', where: { slug: { equals: slug } }, locale: 'all', limit: 1, }); // Check products const productRes = postRes.docs.length === 0 ? await payload.find({ collection: 'products', where: { slug: { equals: slug } }, locale: 'all', limit: 1, }) : { docs: [] }; // Check pages const pageRes = postRes.docs.length === 0 && productRes.docs.length === 0 ? await payload.find({ collection: 'pages', where: { slug: { equals: slug } }, locale: 'all', limit: 1, }) : { docs: [] }; const anyDoc = postRes.docs[0] || productRes.docs[0] || pageRes.docs[0]; if (anyDoc) { // If the doc exists, we can figure out its native locale or // offer the alternative locale (if we are in 'de', offer 'en') const currentLocale = urlPath.startsWith('/en') ? 'en' : 'de'; const alternativeLocale = currentLocale === 'de' ? 'en' : 'de'; suggestedLang = alternativeLocale === 'de' ? 'Deutsch' : 'English'; // Reconstruct the URL for the alternative locale const pathParts = urlPath.split('/').filter(Boolean); if (pathParts.length > 0 && (pathParts[0] === 'en' || pathParts[0] === 'de')) { pathParts[0] = alternativeLocale; } else { pathParts.unshift(alternativeLocale); } suggestedUrl = '/' + pathParts.join('/'); } } catch (e) { // Ignore Payload errors in 404 } } } return ( <> {/* Industrial Background Element */} 404 404 {t('title')} {t('description')} {suggestedUrl && ( Did you mean to visit the {suggestedLang} version? This page exists, but in another language. Go to {suggestedLang} Version )} {t('cta')} Contact Support {/* Decorative Industrial Line */} > ); }
{t('description')}
This page exists, but in another language.