NextJS app router trips/[id]/page.tsx
Hello all,
How do I correctly pull in [id] to page.tsx to console.log and display the id?
How do I correctly pull in [id] to page.tsx to console.log and display the id?
export default function Page({
params,
searchParams,
}: {
params: { slug: string }
searchParams: { [key: string]: string | string[] | undefined }
}) {
return <h1>My Page</h1>
}'use client'
import { useParams } from 'next/navigation'
export default function ExampleClientComponent() {
const params = useParams()
// Route -> /shop/[tag]/[item]
// URL -> /shop/shoes/nike-air-max-97
// `params` -> { tag: 'shoes', item: 'nike-air-max-97' }
console.log(params)
return <></>
}export async function
getServerSideProps(ctx: GetServerSidePropsContext<ParsedUrlQuery, PreviewData>): Promise<{ props: {
id: string,
}}>
{
const id = ctx.query?.id || "";
return ({ props: { id }});
}