I am trying to use dynamic routes such that the URI has blogs/id/
n NextJS 13 project where the id part is supposed to be dynamic, however it seems like it is not working. It seems to always show the page corresponding to blogs.
I have am using the experimental app directory in Next 13 for this project and I have a route blogs
which I set up by creating the layout.jsx
and page.jsx
inside the src/app/blogs/
directory.
I have noticed that the console log statements in the src/app/blogs/[id]/page.jsx
is showing up in the server side console. i.e. the terminal (not the browser console). However, the corresponding JSX in the return statement is not rendering. Instead of that, the JSX corresponding to blogs
is getting rendered.
JSX Code in the project:
src/app/blogs/layout.jsx
import PageTitle from '../components/Title/page-title';
import BlogPage from './page.jsx';
export default function BlogLayout() {
const blogTitle = "My Blog"
return (
<>
<PageTitle title={blogTitle} />
<BlogPage />
</>
)
}
src/app/blogs/page.jsx
function BlogPage() {
return (
<>
<p className="blog-text--paragraph prose text-gray-600">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Consequuntur quaerat a possimus, qui expedita iure, ipsum asperiores aliquid eveniet libero vel architecto! Assumenda incidunt dolore molestiae?
</p>
</>
);
}
export default BlogPage;
src/app/blogs/[id]/layout.jsx
import PageTitle from '../../components/Title/page-title';
import BlogPageMain from '../[id]/page';
export default function DynamicBlogLayout() {
const blogTitle = "BlogPageMain Blog"
return (
<>
<PageTitle title={blogTitle} />
<BlogPageMain />
</>
)
}
src/app/blogs/[id]/page.jsx
export default function BlogPageMain({ params, searchParams }) {
console.log("The current ID is:");
console.log(params.id);
return <div>ID: {params.id}</div>
}
Project and Environment Details:
- Next v13.3.0
- Tailwindcss v3.3.1
- Node v18.15.0
- Yarn v1.22.19
- Ubuntu 22 (Linux)
Screenshots for reference:
Screenshot of blogs/two for Reference
Screenshot of Frontend for reference
I have gone through the official documentation couple of times, but I am not able to understand what is wrong here and why it is not rendering properly. Any help is greatly appreciated.