Dynamic routing with multiple parameters in Next js
Folder structure like this will work
-[blog] //folder name
-[post].js //file name
-items //folder name
-[category] //folder name
-[subCategory].js //file name
you can simply call the blog and post like
<a href="/blog/post"></a>
you can simply call the category and subcategory like
<a href="/items/category/subCategory"></a>
You can do this with the help of dynamic routing in nextjs 9.
For example, pages/post/[postId]/[commentId].js
would match /post/p1/c1
. Its query object would be: { postId: 'p1', commentId: 'c1' }.
your Link component should be like this:
<Link
href="/post/[postId]/[commentId]"
as={`/post/${postId}/${commentId}`}>
<a>link to comment</a>
</Link>
Folder structure should be Like that
Page - Folder
blog - Folder Name
[p1] - Folder Name
[p2].js - File Name
it will work when you call URL like /blog/postname/id it will call p2.js page