How to make sure the middleware applies to routes ?
Unanswered
West African Lion posted this in #help-forum
West African LionOP
What is the best way to apply a middleware to a route('/Admin) for example. ?
https://pastebin.com/Vh18HSRN
https://pastebin.com/Vh18HSRN
24 Replies
@West African Lion What is the best way to apply a middleware to a route('/Admin) for example. ?
https://pastebin.com/Vh18HSRN
so you want your middleware to only trigger for
/admin routes?you can use a [matcher](https://nextjs.org/docs/app/building-your-application/routing/middleware#matcher) to handle that
@joulev so you want your middleware to only trigger for `/admin` routes?
West African LionOP
Im using that, the thing is it doesnt trigger
export const config = {
// Combina los matchers de ambos middlewares
matcher: ["/admin", "/(en|es|ar|fr)/:path*"],
};`@West African Lion Im using that, the thing is it doesnt trigger
hmm can you make the middleware trigger at all on any routes? i feel like your middleware is not correctly configured – your code looks (kinda) fine for me
where is the middleware file located
West African LionOP
On the source
@joulev hmm can you make the middleware trigger at all on any routes? i feel like your middleware is not correctly configured – your code looks (kinda) fine for me
West African LionOP
The next-intl middleware works perfectly, the one for admin doesnt trigger. And i dont know why. Even the console doesnt show anything
that's weird, could you make a [minimal repro repo](https://l.joulev.dev/mrr)?
West African LionOP
so i can clone and try
@West African Lion Click to see attachment
yes this middleware placement is correct
West African LionOP
Yep
Its strange
I can add you to the repository if you want
no, im busy rn so cant read a lot of code. please make a minimal reproduction repo, creating it is easier and faster than you might think
West African LionOP
Never did that
Im gonna try
@joulev no, im busy rn so cant read a lot of code. please make a minimal reproduction repo, creating it is easier and faster than you might think
West African LionOP
I didnt understand on. how to create a minimal repo
Read the link above
West African LionOP
i didi
pnpm install
and dev
thats all ?