-
Hi, I'm new to middlewares and page based routing, and not sure I understand how they should work together. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hi @mrose!
I understand that this is misleading, and this feature might be reworked in the future. To use it in a future-proof manner, you can put the name of the middleware in the filename into parentheses like Also worth mentioning is that your implementation should not expect the framework to process the middleware in a fixed order, especially in development mode with file changes. So, my answer for now is that middlewares are running on each request, even on API routes! |
Beta Was this translation helpful? Give feedback.
Hi @mrose!
.middleware.ts
(starting with a dot) is only the extension of the file, so it's eithermiddleware.ts
orname.middleware.ts
, wherename
is not affecting on which route the middleware is active, but only to help you navigate in your project and put your middleware logic in multiple files. You can use theuseMatch
function from@lazarv/react-server/router
to check if your currentpathname
should be processed in the middleware. See an example in the docs app at https://github.com/lazarv/react-server/blob/main/docs/src/pages/i18n.middleware.mjs, but even the docs is proposing this approach at https://react-server.dev/router/middlewares.I understand that this is misleading, and this…