Next.js Discord

Discord Forum

The middleware.ts not working in custom app directory

Answered
Turkey Vulture posted this in #help-forum
Open in Discord
Avatar
Turkey VultureOP
the middleware is on the root directory of app but it not working. if i moved into src it worked. so weird
Answered by Z4NR34L
if you are using app directory at root, migrate everything out from src, or opposite, your middleware.ts should be always in same level as app or pages directory (if you use src dir, put it inside)
View full answer

5 Replies

Avatar
Turkey VultureOP
Image
Avatar
Z4NR34L
You can have src or app directory, never both in same tree level
Avatar
Z4NR34L
if you are using app directory at root, migrate everything out from src, or opposite, your middleware.ts should be always in same level as app or pages directory (if you use src dir, put it inside)
Answer
Avatar
Turkey VultureOP
ah thanks @Z4NR34L
Avatar
Z4NR34L
No problem! If that solved your problem, please mark a message as the answer for your post with Right click -> Apps -> Mark Solution