Next.js Discord

Discord Forum

Thought Process: Dynamic Routes Blog Page is Similar to Layout?

Answered
Common paper wasp posted this in #help-forum
Open in Discord
Common paper waspOP
This is probably really stupid but I was going through changing my blog from Astro to Next today and I was working on setting up my slug pages and in blog/[slug] I have my page.tsx and hooked some things up to Velite to make sure it displays. All good there. But I also have a layout.tsx that is not doing really anything other than setting the outer parent element of article and inside that is the children, which would just be the blog post.

But if I'm able to get the post metadata/frontmatter in the page.tsx, am I wrong to see that sort of as the "layout" for a blog post? Even though it isn't a layout.tsx the way Next would describe it?
Answered by joulev
the page component is rendered in the children part of the layout component. not sure what you are trying to do with your frontmatter
View full answer

12 Replies

Common paper waspOP
So I could put what's in that layout into my slug pages instead?
not sure what you mean but does it depend on the slug? if yes, most likely you'd want to put it in the page
Common paper waspOP
Sorry I'm not meaning to be dense. The slug page needs to output the frontmatter information of the post in a styled manner and the layout right now doesn't have anything that I don't think couldn't go in the slug page to define how the post should be rendered
Answer
Common paper waspOP
Yeah but if I don't have that layout then it'll be rendered in the children of the parent layout, right?
Which means I could move that article to my slug page, delete the slug layout, and it'll look the same
Right?
in this particular case, yes
Common paper waspOP
Lol nice. I get mixed up with what should go in which layout or in the page with these types of systems
Never know when something should go in the layout vs the page