Staaarter

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.

By Staaarter Team
Error
Docs
Live preview

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.json

Prefer 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

PropTypeDefaultDescription
headingstring"Page not found"Main heading.
descriptionstring"You'll be redirected to the homepage automatically, or you can go now."Short explanation under the heading.
redirectSecondsnumber10Starting value of the countdown, in seconds.
redirectHrefstring"/"Link target for the manual "Go now" button.
onRedirect() => void() => {}Called exactly once when the countdown reaches zero.
classNamestringnoneExtra 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.