-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How do you render the not-found
page?
#36
Comments
This is a duplicate of #32. But I'll elaborate and show a workaround here. Essentially the issue is that automatic redirects to Another problem is that inside of your These are not issues specific to next-i18n-router. They are quirks in Next.js app router. You will need:
[...not_found]/page.tsx:
not-found.tsx:
|
@i18nexus x-i18n-router-locale always seems to be null, is there any requirement for it? I'm using 5.0.2. |
@Zerebokep Sorry, just saw this. The most common reason this occurs is that the middleware is not running. If you are using the
If neither of these solve your problem, please paste your |
@i18nexus No worries. this is my middleware.ts which is inside the src/app/ folder
btw. I'm still using the "old" useEffect method of the TranslationProvider, maybe this has something to do with it? |
@Zerebokep Ah, your problem is that your middleware needs to be outside of the Side note, I highly recommend switching to the new version of the i18next example. It's quite easy to change. |
@i18nexus oh my bad, it is actually there, I misdescribed it in my earlier post. |
@Zerebokep Can you put a console log in your middleware function to make sure its being called? |
@i18nexus Yes, middleware is definitely running. I've also put |
@Zerebokep Oh shoot, sorry I wrote the header wrong in my original comment. It should be |
Haha, all good, it works for me now, thanks for checking it out :) |
Hey @i18nexus ! Your suggested solution works, but it broke my SSG routes. Any ideas why this might be? Removing import { headers } from 'next/headers';
const headersList = headers();
const locale = headersList.get('x-next-i18n-router-locale') Seems to fix it, so the issue might be with the header trick? 🤔 |
@yannjor Can you elaborate on what you mean by it breaking your SSG routes? Any error messages? |
@i18nexus of course, sorry my original message was not so clear. This is how I'm trying to render the not-found page. import React from 'react';
import styles from './NotFoundPage.module.css';
import Hero from '@/components/Hero';
import { PrismicRichText } from '@prismicio/react';
import typography from '@/styles/typography.module.css';
import i18nConfig from '@/i18nConfig';
import { fetchSingleStaticPage } from '@/model/staticPage/fetch';
import { headers } from 'next/headers';
export default async function NotFound() {
const headersList = headers();
const locale =
headersList.get('x-next-i18n-router-locale') || i18nConfig.defaultLocale;
const page = await fetchSingleStaticPage('not-found', locale);
return (
<main>
<Hero doc={page} />
<article className={styles.notFound}>
<p className={typography.body2}>
<PrismicRichText field={page.description} />
</p>
</article>
</main>
);
} and import { notFound } from 'next/navigation';
export default function NotFoundCatchAll() {
notFound();
} When I build the app, everything looks good, no error messages, except that when I look in the built |
Interesting, we'll look into this. Are you using |
Yes |
@i18nexus It says in the Next.js docs that: " So perhaps this is the reason. |
Sorry on the delay digging into this. But in the meantime, I think this comment may be the best solution. But again, we will look further into this by next week and report if there's a better solution. This thread is basically a bunch of people with the same problem. |
@i18nexus I found this workaround that works: vercel/next.js#43179 (comment) |
I cannot find a way to implement the
not-found
page with this folder structure in the App router.The text was updated successfully, but these errors were encountered: