Next.js Discord

Discord Forum

How to access the parent page's slug?

Answered
Asian paper wasp posted this in #help-forum
Open in Discord
Avatar
Asian paper waspOP
I have a topic and page number. I want fetch the topic and the page number from an API but I don't know how to access the topic from the [pageNumber] page. How should I do it?
type Props = {
    params: {
        pageNumber: string;
    };
};

export default function TopicPage(props: Props) {
    return <div>TopicPage</div>;
}
Image
Answered by not-milo.tsx
You don't need to do anything. It will be passed down to your page as part of its parameters.

See: https://nextjs.org/docs/app/building-your-application/routing/dynamic-routes#typescript

Here you can see a clear example. Plus at the top of the page you can find this piece of text:

Dynamic Segments are passed as the params prop to layout, page, route, and generateMetadata functions.
View full answer

2 Replies

Avatar
not-milo.tsx
You don't need to do anything. It will be passed down to your page as part of its parameters.

See: https://nextjs.org/docs/app/building-your-application/routing/dynamic-routes#typescript

Here you can see a clear example. Plus at the top of the page you can find this piece of text:

Dynamic Segments are passed as the params prop to layout, page, route, and generateMetadata functions.
Answer
Avatar
Asian paper waspOP
Thank you @not-milo.tsx