首页 > 解决方案 > 如何在使用下一个路由器时解决未处理的运行时错误

问题描述

我在使用useRouterfrom时遇到以下错误next/router

TypeError: Cannot read property 'getBoundingClientRect' of null

import React from 'react'
import Link from 'next/link'
import { useRouter } from 'next/router'

function ActiveLink({ children, href, activeClassName }) {
  const { asPath } = useRouter()
  console.log(asPath)

  return (
    <Link href={href} />
  )
}

export default ActiveLink

标签: reactjsnext.jsnext-router

解决方案


推荐阅读