Suppose you have a simple case of a marketplace site, and you have different categories, like fruits, electronics, etc.
I want to create a page for each category. My question is, is it better to use categoryId as the dynamic page name, or the categorySlug, for instance?
localhost:3000/categories/{WHAT GOES HERE?}
Thoughts: If I use categoryId, I can use this ID to get the data from the DB whilst on the page. However, it's a ugly long piece of string in the URL.
Using a slug is possible as well, and I see sites do things like /categories/usedCars-1199
to ensure that the slugs are unique, so that this value can then be used to get the data from a database.
Can someone with experience validate my hypothesis that using a unique slug value is better because 1) it's human readable, providing better SEO and better URL experience, and 2) you can still use the slug value as filter to get data?
I tried using the categoryName, which was a mistake because this field is non-unique - implying that I couldn't use it to target the data in the DB. I then had to create a global state to select the right category ID to use as DB filter whilst on page, and this felt like a wasteful process.
Have not tried using a unique slug, but this seems like the most reasonable approach.