404 With Redirect Countdown
A 404 screen with a live redirect countdown: a heading and explanation, a ticking seconds counter that calls an onRedirect callback exactly once when it reaches zero, a Cancel button that stops the timer, and a manual Go now link.
Docs
Installation
A real shadcn registry command, not a copy-paste stand-in: it fetches this block plus its button dependencies and any missing npm packages, and installs them straight into your project.
npx shadcn add https://staaarter.com/r/404-with-redirect-countdown.jsonPrefer not to use the CLI? Copy the source from the Code toggle above into src/components/blocks/error/error8.tsx instead.
Usage
The file also exports error8Demo, the exact props behind the preview above. Spread it to get a working section in one line, then replace it with your own data.
import { Error8, error8Demo } from "@/components/blocks/error/error8"; export default function Page() { return <Error8 {...error8Demo} />; }
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| heading | string | "Page not found" | Main heading. |
| description | string | "You'll be redirected to the homepage automatically, or you can go now." | Short explanation under the heading. |
| redirectSeconds | number | 10 | Starting value of the countdown, in seconds. |
| redirectHref | string | "/" | Link target for the manual "Go now" button. |
| onRedirect | () => void | () => {} | Called exactly once when the countdown reaches zero. |
| className | string | none | Extra classes for the outer section element. |
Behavior notes
- The countdown is a real client-side timer: a setInterval created in useEffect decrements local state once per second; when it reaches zero it clears itself and calls onRedirect exactly once, guarded by a ref so a later re-render can't call it twice.
- Cancel is a real handler: it clears the interval (via the effect's cleanup) and swaps the countdown text for a static "cancelled" message, no further ticking happens after that.
- "Go now" is a real Next.js Link via the button's render prop that navigates to redirectHref immediately if clicked, it does not itself call onRedirect, that callback only fires from the countdown reaching zero.
More Error Blocks
View all →centered-404-message
Centered 404 Message
Minimal centered 404 with two CTAs and a divided row of popular page links.
404-with-site-search
404 With Site Search
404 screen with a working search box and a bordered list of suggested pages.
split-404-with-image
Split 404 With Image
Two-column 404 with the message on one side and a full-bleed photo that scales on hover on the other.
404-with-destination-cards
404 With Destination Cards
404 screen with a grid of icon destination cards plus fallback CTA buttons.
404-support-panel
404 Support Panel
Card-style 404 echoing the requested URL, with a real back button and a support/status link row.
inline-404-line
Inline 404 Line
The smallest possible 404: code and message on one divided line with one button underneath.