Nicoolas
(Nicolas Fiascaro)
March 19, 2024, 3:47pm
1
Multi lang website with App router from Next.js 14, deployed on Vercel. I will be curious to see other projects with the same configuration.
Website URL
https://www.nicolas-fiascaro.com/
A screen shot of the site
Technologies used
CMS: Prismic
Framework: Next.js | Tailwind
Motion: ReactFramer
Hosting: Vercel
Industry
Design
Utilizes Slice Machine?
Absolutely
Time to build
Severals days for the main structure. And iterate on some edge cases
An interesting feature or challenge you solved for
It seems that Next.js projects with multi lang and app router are not so common!
And keeping a dark mode in the user session without glitches is not as simple as we think !
1 Like
Looks awesome, thank you for sharing!
I just visited it again today, and it looks like it's 404ing, you might want to have a look at what broke
Definitely noting this for a futur tutorial from the team! Thanks for the idea!
Nicoolas
(Nicolas Fiascaro)
March 20, 2024, 2:51pm
3
Hi @nouha.chhih
Thanks for your feedback and i'm curious to know how you get the 404.
Because normally there is a redirection made in nextjs middleware, handled by a function made by the prismic team, here : feat: add `createLocaleRedirect()` to simplify i18n routing by angeloashmore · Pull Request #89 · prismicio/prismic-next · GitHub
Can you visit here without 404 ? https://www.nicolas-fiascaro.com/en-us
i actually follow a blog post about this topic: Next.js Internationalization (i18n) Tutorial [App Router]
Best,
Hey @Nicoolas
Yes https://www.nicolas-fiascaro.com/en-us works fine! Maybe @Levi or @Phil can help you out with this one!
1 Like
Phil
(Phil Snow)
March 21, 2024, 2:03pm
6
Hi Nicolas,
I'm not sure off the top of my head as to why your root URL isn't redirecting, I would need to see your code to investigate.
If you compare your project to our sample project it might help you debug
Thanks.
Nicoolas
(Nicolas Fiascaro)
March 21, 2024, 8:43pm
7
Hi @Phil ,
Honestly i have already check and i don't find differences.
But on my differents browsers i have the redirection on the root url, with private mode or session cleared, it's confusing.
You can find my code here : GitHub - Cocola/nf-nextjs-prismic: Personal website
Thanks
Phil
(Phil Snow)
March 22, 2024, 12:03pm
8
Maybe try the custom middleware to see if that changes anything:
// ./src/middleware.ts
import { NextRequest, NextResponse } from 'next/server';
import { createClient } from '@/prismicio';
export async function middleware(request: NextRequest) {
const client = createClient();
const repository = await client.getRepository();
const locales = repository.languages.map((lang) => lang.id);
const defaultLocale = locales[0];
// Check if there is any supported locale in the pathname
const { pathname } = request.nextUrl;
const pathnameIsMissingLocale = locales.every(
(locale) => !pathname.startsWith(`/${locale}/`) && pathname !== `/${locale}`
);
// Redirect to default locale if there is no supported locale prefix
if (pathnameIsMissingLocale) {
return NextResponse.rewrite(
new URL(`/${defaultLocale}${pathname}`, request.url)
);
}
}
export const config = {
// Don’t change the URL of Next.js assets starting with _next
matcher: ['/((?!_next).*)'],
};
1 Like
Nicoolas
(Nicolas Fiascaro)
March 22, 2024, 1:02pm
9
It works ! thank you @Phil !
1 Like