79471562

Date: 2025-02-27 03:56:06
Score: 0.5
Natty:
Report link

For anyone looking for a solution like the one @juliomalves gave, and one that doesn't involve the use of middleware on every request, you can:

  1. generateStaticParams as dynamic routes (statically generated) as explained here: use generateStaticParams() in layout.tsx NextJS 14 app directory to get dynamic rotes prerendered (PPR)
  2. rewrite the paths dynamically if you want to get the default locale at "/" (instead of "en/" for example if your default locale is English):
    const nextConfig = {
      ...
      async rewrites() {
        return [
          // Handle all paths that don't start with a locale 
          // and point them to the default locale static param: (en)
          {
            source: '/:path((?!(?:de|fr|es|it|el|pl|nl|en)(?:/|$)).*)',
            destination: '/en/:path*',
          },
        ];
      },
    };
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • User mentioned (1): @juliomalves
  • Low reputation (0.5):
Posted by: Jack Tsin