I searched for this but I could only find examples in Laravel and PHP, and I need to know how to do this with Next.js.
All I know is that I can do dynamic routes in Next.js the usual way like this ...
/pages/post/[postId]
which will translate to /pages/post/23435
for example, and that way if someone has the URL I could just grab the [postId]
with router.query
and can show the correct post to the user, easy enough.
But what if I want to show the post name in the URL instead of the id? just like what Udemy does with dashes between the words ...
https://www.udemy.com/course/your-custom-react-component/learn/lecture/
And at the same time if someone has that URL I could still show the correct post to them?
I know I could just do /pages/post/[postName]
and show the post name in the URL, but that won't be unique, and won't be able to show the correct post.
How can I do that?