nextjs: TypeError: Cannot read properties of null (reading 'push')

I use sweetalert2 for show popup:

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

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

After show opopup I clicked on TEST and I get this error:

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

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

Without sweetalert2, <Link> work fine, but with sweetalert2 I get error

>Solution :

Please try to this;

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


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

Leave a Reply