404 Page
Learn how to create custom 404 pages for unmatched routes in Bini.js.
Bini.js provides a built-in 404 page, but you can create custom not-found.tsx files to display your own UI when a route is not found.
Global 404 Page
Create a not-found.tsx file in the root of your app directory to handle all unmatched routes globally.
This page will be shown for any unmatched route, such as /non-existent or /blog/invalid-post.
Nested 404 Pages
You can create route-specific 404 pages by placing not-found.tsx in subdirectories. The closest 404 page to the matched route will be used.
| URL | 404 Page Used |
|---|---|
| /blog/non-existent | app/blog/not-found.tsx |
| /admin/invalid | app/admin/not-found.tsx |
| /completely/wrong | app/not-found.tsx (global) |
Programmatic 404
You can manually trigger a 404 page from within your components when data is not found.
404 with Layout
404 pages are automatically wrapped with the layout chain of the route they belong to.
This means your 404 pages automatically inherit headers, footers, and other shared UI from layouts.
Styling 404 Pages
You can create rich, styled 404 pages with images, animations, and interactive elements:
Static Export & 404
When using npm run export for static hosting, Bini.js generates a 404.html file:
| Situation | Generated 404.html |
|---|---|
| not-found.tsx exists | Copy of index.html with your custom 404 page |
| No not-found.tsx | Redirect script that preserves the URL and redirects to / |
This ensures your SPA works correctly on static hosts like GitHub Pages, Netlify, and Vercel.