loliki
loliki

Reputation: 957

NextJS specific dynamic routes

I'm building a small application and want to build a simple routing system but I got into a small issue.

I have my category page which is dynamic, and a single post which will be category/post-name now I want that my category page to be only accessible when the user goes to website.com/category1/ or website.com/category2/ or website.com/category3/ but not on other dynamic routes.

Is there a way to do it?

Upvotes: 1

Views: 715

Answers (1)

Alok p
Alok p

Reputation: 629

Predefined routes take precedence over dynamic routes, and dynamic routes over catch all routes. For example:

  1. pages/category/category1.js - Will match /category/category1
  2. pages/category/caregory2.js - Will match /category/category2
  3. pages/category/category3.js - Will match /category/category3
  4. pages/category/[category_id].js - Will match /category/category4, /category/category5, etc. But not /category/category1, /category/category2, /category/category3.

Upvotes: 1

Related Questions