【问题标题】:nextjs: TypeError: Cannot read properties of null (reading 'push')nextjs:TypeError:无法读取 null 的属性(读取“推送”)
【发布时间】:2022-02-08 13:26:08
【问题描述】:

我使用sweetalert2 来显示弹出窗口:

export default function Home() {
    const MySwal = withReactContent(Swal)
    
    useEffect(() => {
        MySwal.fire({
            showConfirmButton: false,
            customClass: {
                container: "swalPopup"
            },
            html:<Link href={"/profile/dashboard"}><a>TEST</a></Link>,
        })
    }, []);

    return ('<div>Home</div>')
}

显示弹出窗口后,我点击TEST 并收到以下错误:

Unhandled Runtime Error
TypeError: Cannot read properties of null (reading 'push')

Call Stack
linkClicked
node_modules/next/dist/client/link.js (50:11)
onClick
node_modules/next/dist/client/link.js (200:16)

没有sweetalert2&lt;Link&gt; 可以正常工作,否则我会收到错误消息。

【问题讨论】:

    标签: javascript reactjs next.js


    【解决方案1】:

    请试试这个;

    <Button type="button" onClick={(e) => router.push('/profile/dashboard')}>
    Test
    </Button>
    

     <Link href="/">
            <a onClick={(e) => handleClick(e, "//profile/dashboard")}>Test</a>
          </Link>```
    
    

    【讨论】:

    • 第一种方式工作正常。谢谢
    猜你喜欢
    • 2014-12-04
    • 2022-01-16
    • 1970-01-01
    • 2021-01-19
    • 2020-12-28
    • 1970-01-01
    • 2020-04-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多