Comments (7)
I just apply change following the official documentation from next-intl and Clerk. Applying without giving a thought. Indeed, it can create an issue for /api
route
I just recheck the official documentation from next-intl
, if I'm not wrong, they never mention about Route Handlers. I think Everybody will should have the same issue using next-intl
, this not specific to the boilerplate, right?
Another solution is to place /api/guestbook inside [locale]
folder, also not sure if it's working and not sure it's a good solution.
You potential fix can be a solution, does it have some side effect?
from next-js-boilerplate.
I found this page in the documentation: https://next-intl-docs.vercel.app/docs/environments/metadata-route-handlers#route-handlers
from next-js-boilerplate.
Even I never do translation in /api, I think most of the users will expect to have translation also available in Route Handler. So, they can also translate in Router Handler by moving it inside [locale]
, what do you think?
One of the official example, the route handler is inside [locale]
: https://github.com/amannn/next-intl/blob/4572f9666e3ba2da81e78851967865e5e860fd3d/examples/example-app-router-playground/src/app/%5Blocale%5D/api/route.ts
from next-js-boilerplate.
You potential fix can be a solution, does it have some side effect?
At least in my current use, it doesn't have any visible issues.
I found this page in the documentation: https://next-intl-docs.vercel.app/docs/environments/metadata-route-handlers#route-handlers
I briefly looked at the documentation and the example. I think it only requires that we pass the locale into the getTranslations
function, and it doesn't matter where the locale
is obtained from.
So I think both of them (extracting locale
from header or searchParams, or putting Route Handler into [locale]
) are feasible solutions.
The cause of the problem is probably that Intl Middleware will try to rewrite all requests to /en
, which works fine in [locale]
, but since the Route Handler does not inside [locale]
, this will cause a 404 error. Changing localePrefix
to always
makes this behavior more obvious.
I think both of the following two solutions can solve this:
- Skip Intl Middleware for API Routes and get the locale from header or other sources.
- Move API Routes into
[locale]
and get the locale from route segment.
Perhaps the 2. is a more intuitive one for regular users? Not sure.
from next-js-boilerplate.
Perhaps the 2. is a more intuitive one for regular users? Not sure.
I also think it's more intuitive and regular users.
Already not a huge fan about these 2 lines in the middleware: https://github.com/ixartz/Next-js-Boilerplate/blob/main/src/middleware.ts#L15-L16. So, if we can avoid make any custom change in the middleware, it would be great.
Do you think you can open a PR for the 2. solution?
from next-js-boilerplate.
Do you think you can open a PR for the 2. solution?
Sure.
from next-js-boilerplate.
🎉 This issue has been resolved in version 3.30.1 🎉
The release is available on GitHub release
Your semantic-release bot 📦🚀
from next-js-boilerplate.
Related Issues (20)
- Errors with PNPM straight out of the box HOT 7
- Migrating to Vitest HOT 8
- Minor typo HOT 1
- Sign-up and Sign-in meta descriptions should be swapped HOT 1
- Add `.devcontainer/devcontainer.json HOT 5
- Image quality HOT 3
- Custom SignOutButton currently not being used HOT 5
- Confusing naming between Schema and Validation. HOT 6
- Error: Cannot find module './sw.js.json' HOT 4
- add additional authentication options (not just clerk) HOT 5
- Sentry Auth token HOT 1
- Guide to remove certain dependencies? HOT 2
- How to integrate state management in Zustand with NextJS HOT 1
- Sitemap HOT 9
- Feature request: Turborepo and Documentation HOT 7
- How can we replace tailwindcss with unocss? HOT 1
- Is possible to dockerize application base on this project ?
- Is possible to dockerize application base on this project ? HOT 1
- How I use SSR? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from next-js-boilerplate.