Scott

nextjs路由跳转 a year ago

react
nextjs
460个字符
共有81人围观

一般情况下:

// next/link
<Link href="/dashboard" scroll={false}>
  Dashboard
</Link>

使用useRouter() Hook

'use client'
 
import { useRouter } from 'next/navigation'
 
export default function Page() {
  const router = useRouter()
 
  return (
    <button type="button" onClick={() => router.push('/dashboard')}>
      Dashboard
    </button>
  )
}

想了解更多,请参看:https://nextjs.org/docs/app/building-your-application/routing/linking-and-navigating