MCPcopy Create free account
hub / github.com/dailydotdev/apps / routeHandler

Function routeHandler

packages/shared/src/hooks/useExitConfirmation.ts:43–64  ·  view source on GitHub ↗
(url: string, { shallow }: { shallow?: boolean })

Source from the content-addressed store, hash-verified

41 };
42
43 const routeHandler = (url: string, { shallow }: { shallow?: boolean }) => {
44 // Shallow changes on the same page (e.g. ?tab=) leave nothing behind.
45 if (
46 shallow &&
47 new URL(url, window.location.href).pathname === window.location.pathname
48 ) {
49 return;
50 }
51
52 const shouldAskConfirmation = checkShouldAskConfirmation();
53
54 // eslint-disable-next-line no-restricted-globals,no-alert
55 if (shouldAskConfirmation || confirm(message)) {
56 return;
57 }
58
59 router.events.emit('routeChangeError');
60 // Throwing a string (not an Error) is Next.js's documented way to abort a
61 // route change without triggering the dev error overlay.
62 // eslint-disable-next-line @typescript-eslint/no-throw-literal
63 throw 'Route change aborted by useExitConfirmation. Please ignore this error.';
64 };
65
66 window.addEventListener('beforeunload', closeHandler);
67 router.events.on('routeChangeStart', routeHandler);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected