-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d708773
commit 8f269be
Showing
7 changed files
with
81 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { Track404 } from 'components/Track404' | ||
|
||
// Defining it in a catch all route allows for it to be wrapped by the root layout | ||
export default function NotFound(): JSX.Element { | ||
return <Track404 /> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
'use client' | ||
|
||
import { useRouter } from 'next/navigation' | ||
import { useEffect } from 'react' | ||
|
||
export interface RedirectProps { | ||
to: string | ||
} | ||
|
||
export function Redirect({ to }: RedirectProps): React.ReactNode { | ||
const router = useRouter() | ||
useEffect(() => { | ||
void router.replace(to) | ||
}, [router, to]) | ||
return null | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
'use client' | ||
|
||
import { useAnalytics } from 'lib/analytics' | ||
import { Redirect } from './Redirect' | ||
import { useEffect } from 'react' | ||
|
||
export function Track404(): JSX.Element { | ||
const { track404 } = useAnalytics() | ||
|
||
useEffect(() => { | ||
track404() | ||
}, [track404]) | ||
|
||
return <Redirect to="/" /> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
'use client' | ||
|
||
import { usePlausible } from 'next-plausible' | ||
import { useRef } from 'react' | ||
|
||
type Analytics = { | ||
'404': { path: string } | ||
} | ||
|
||
export function useAnalytics(): { track404(): void } { | ||
const notFoundTracked = useRef(false) | ||
const plausible = usePlausible<Analytics>() | ||
return { | ||
track404: () => { | ||
if (!notFoundTracked.current) { | ||
plausible('404', { props: { path: document.location.pathname } }) | ||
notFoundTracked.current = true | ||
} | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters