Answers for "useRouter next"

3

router nextjs

import { useRouter } from 'next/router'

function ActiveLink({ children, href }) {
  const router = useRouter()

  const handleClick = (e) => {
    e.preventDefault()
    router.push(href)
  }

  return (
    <a href={href} onClick={handleClick} style={style}>
      {children}
    </a>
  )
}

export default ActiveLink
Posted by: Guest on November-16-2020
0

userouter next js

import { useRouter } from "next/router"

export default function Doc() {
    const router = useRouter();
    const { params = [] } = router.query;

    if (params.length === 2) {
        return (
            <h1>
                Viewing docs for feature {params[0]} and concept {params[1]}
            </h1>
        )
    } else if (params.length === 1) {
        return <h1>Viewing docs for feature {params[0]}</h1>
    }

    return <h1>Docs Home Page</h1>
}
Posted by: Guest on November-06-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language