How to implement middleware in Next.js? #127572
-
Select Topic AreaProduct Feedback BodyThis is my home page, I have a button that routes to a page called redirect, it creates a cookie while routing:
Here's what I have so far in my middleware:
It checks if the cookie exists, if it doesn't I want it to redirect back to the homepage. I do have the file (middleware.ts) in my root folder. Sadly it isn't working and I'm not sure why. Spent the whole afternoon on yt, documentation, etc. I'm just a casual programmer so pardon me if this is too easy to figure out. I'd appreciate any help |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
This can be helpful for you. |
Beta Was this translation helpful? Give feedback.
This can be helpful for you.
https://nextjs.org/docs/app/building-your-application/routing/middleware