Not Found Terminal

A page-not-found screen drawn as a terminal that answers a typed page name with a link.

$ open /docs/api/webhoks

error: page not found

No page lives at this address.closest match: /docs/api/webhooks# try/docs · every guide/docs/api · API reference/changelog · what moved and when
'use client';

import { NotFoundTerminal } from '@brand-studio/ui';

const links = [
  { href: '/docs', title: 'every guide' },
  { href: '/docs/api', title: 'API reference' },
  { href: '/changelog', title: 'what moved and when' },
];

// The links point at pages of a made-up docs site, so the demo keeps clicks on this page.
export default function NotFoundTerminalDemo() {
  return (
    <div onClickCapture={event => { if ((event.target as HTMLElement).closest('a')) event.preventDefault(); }} style={{ width: '100%', display: 'grid', justifyItems: 'center' }}>
      <NotFoundTerminal
        as="h2"
        name="roastery docs"
        path="/docs/api/webhoks"
        links={links}
        pages={['/docs/api/webhooks', '/docs/api/orders', '/docs/getting-started']}
        search="/search"
      />
    </div>
  );
}

Installation

pnpm add @brand-studio/ui

Usage

import { NotFoundTerminal } from '@brand-studio/ui';
<NotFoundTerminal
  name="roastery docs"
  links={[{ href: '/docs', title: 'every guide' }, { href: '/changelog', title: 'what moved and when' }]}
  pages={sitemapPaths}
  search="/search"
/>

It prints the missing address, the closest of links and pages when the address looks like a typo, and links as places to try. A typed page name gets a link to the matching page. With no match, it links to search with the typed words.

Accessibility

  • The heading names the error in words, and every place to go is a real link.
  • New answers are added to a log region, so screen readers hear each one once.
  • The prompt has a label for screen readers; the dollar sign is decoration.

API Reference

PropTypeDefault
path?string–
links?NotFoundLink[]–
pages?string[]–
name?string'site'
title?string'error: page not found'
description?string'No page lives at this address.'
search?string–
inputLabel?string'Type a page name'
as?React.ElementType–
className?string''

Still, Deskhand and Hollis are fictional brands. The coffee photographs are original generated artwork. @brand-studio/ui is MIT licensed.