Optionally add locale before basepath #25883
Replies: 10 comments
-
we also hit the same roadblock in our setup. |
Beta Was this translation helpful? Give feedback.
-
any ideas on how to solve it? when I add /app in next/router next/link href it will give me URL /[locale]/app/pageName |
Beta Was this translation helpful? Give feedback.
-
I have just faced this problem today and it's a massive blocker for our use case. |
Beta Was this translation helpful? Give feedback.
-
I would love to see something like the following syntax when |
Beta Was this translation helpful? Give feedback.
-
so in the end what we did was using middleware to set locale (we get it via a header value from our nginx setup). So new middleware came to the rescue on this. And instead of using and in import { NextRequest, NextResponse } from 'next/server';
export function middleware(req: NextRequest) {
const { pathname } = req.nextUrl;
const locale = req.headers.get('X-Locale') || 'en';
const hostname = req.headers.get('host');
const newUrl = new URL(`${locale}${pathname}`, `https://${hostname}/`);
return NextResponse.rewrite(newUrl.toString());
} |
Beta Was this translation helpful? Give feedback.
-
@borantula this solution works if you do not use _next/image optimization pipeline / API. |
Beta Was this translation helpful? Give feedback.
-
We are exactly in the same situation and would use right away that basePath option if available |
Beta Was this translation helpful? Give feedback.
-
Also running into this issue, where we want /pl-pl/shop for example which doesn't seem to be possible. |
Beta Was this translation helpful? Give feedback.
-
Is this item in the roadmap? |
Beta Was this translation helpful? Give feedback.
-
bump |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Describe the feature you'd like to request
We have several apps on the same domain and we have a requirement that locale is the first part of the path.
https://example.com/en/app1/page
https://example.com/en/app2/page
We would like to use bathPath and i18n routing together, it looks like we'd have to rearrange our urls to be
https://example.com/app1/en/page
https://example.com/app2/en/page
Describe the solution you'd like
Add an option in next.config.js that can reverse basePath and locale.
Describe alternatives you've considered
Our current solution to accomplish this url pattern a bit convoluted.
pages/[language]/app1/page1.jsx
assetPrefix
so that our load balancer knows which app to point to for static assetsassetPrefix: /app1
This works fine except for any calls to
/_next/data
. Since those calls intentionally do not get assetPrefix added, our load balancer does not know where to send those requests. BasePath would be the solution, but then our url structure would need to change.Beta Was this translation helpful? Give feedback.
All reactions