rsnext/test/integration/route-load-cancel-css/pages/index.js
Joe Haddad 9acd001e09
Fix render cancel behavior (#16462)
This pull request correctly tracks render cancelation behavior. Prior to this PR, we'd have an unhandled rejection that left the app in a bad state and no routeChangeError event was fired.

---

Closes #16424
Fixes #16445
2020-08-22 11:47:21 +00:00

26 lines
564 B
JavaScript

import Link from 'next/link'
import { useRouter } from 'next/router'
import React, { useEffect } from 'react'
export default () => {
const router = useRouter()
useEffect(() => {
router.events.on('routeChangeError', (err) => {
if (err.cancelled) {
window.routeCancelled = 'yes'
}
})
// Intentionally is not cleaned up
}, [router.events])
return (
<>
<Link href="/page1">
<a id="link-1">Page 1</a>
</Link>{' '}
<Link href="/page2">
<a id="link-2">Page 2</a>
</Link>
</>
)
}