Categories
Next.js

Next.js Dynamic Routes Example

// pages/user/[id].tsx
import { useRouter } from 'next/router';

const User = () => {
  const router = useRouter();
  const { id, ...rest } = router.query;

  return (
    <>
      <h1>User Id is {id}</h1>
      <pre>{JSON.stringify(rest)}</pre>
    </>
  )
}

export default User;

Ref: EggHead

Leave a Reply

Your email address will not be published.