NextJS URL params like React-Router

前端 未结 5 1230
一整个雨季
一整个雨季 2021-02-19 06:56

I\'m a newbie to NextJS, It looks so good on the first impression. But after giving it a chance I\'ve faced some problems like URL routing with custom params like react-router.<

5条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-19 07:52

    For anyone arriving late to this party, we now have dynamic routing in Next 9.

    Which would allow for a url structure to be crafted like this by using the file structure, and without additional packages.

    You could create a file pages/user/[id].js

    With

    import { useRouter } from 'next/router'
    
    const User = () => {
      const router = useRouter()
      const { id } = router.query
    
      return 

    User: {id}

    } export default User

提交回复
热议问题