Capture errors or detour events
const [ parts, query, { trap } ] = useRouter;
trap('error', err => {
setLastError(err);
parts.splice(0);
return false;
})
const [ parts, query, { trap } ] = useRouter;
trap('detour', err => {
setTimeout(() => {
if (confirm('Are you sure you want to leaving this page?')) {
err.proceed();
} else {
err.prevent();
}
}, 50);
return true;
})
type
- "error" or "detour"cb
-<Function>
Callback function
A detour trap will only receive RouteChangePending
objects. It should
return true
if it intends to make a decision on whether to proceed with the detour. Navigation will be
blocked until proceed
or prevent
is called.
An error trap should return a boolean if it has handled the error. This disables the default error handling
mechanism. A return value of true
means the error boundary can attempt to reconstruct the component tree
(i.e. the error is fixed). false
means the error boundary should render nothing until it's given a new
component tree.