Next.js Discord

Discord Forum

[App router] get nextjs slug from middleware

Answered
Narrow-barred Spanish mackerel posted this in #help-forum
Open in Discord
Narrow-barred Spanish mackerelOP
i need to know if the pathname is from a slug or not. e.g. a user visits /example1, and its a static path, and /example2 but its a dynamic slug from [example], i need to be able to detect which is which in the nextj.s middleware
Answered by Narrow-barred Spanish mackerel
yeah, i want it to be automated tho so i dont need to update that list whenveer i add a new static page
i did it now as i dont see any other soluition
View full answer

5 Replies

American black bear
What are you trying to achieve
You can create an object that contains all static paths and then if path is not in that object/array you can deduce that its from a slug
@American black bear You can create an object that contains all static paths and then if path is not in that object/array you can deduce that its from a slug
Narrow-barred Spanish mackerelOP
yeah, i want it to be automated tho so i dont need to update that list whenveer i add a new static page
i did it now as i dont see any other soluition
Answer
American black bear
that is probably the best solution since you don't want to do any heavy work in the middleware