File-Based Routing
Flat files in src/app directly create URL routes without needing a folder.
Overview
Bini.js supports file-based routing - a file directly inside src/app/ becomes a route. No folder needed. For example about.tsx creates /about.
This is different from folder-based routing where you need about/page.tsx. File-based is faster for single pages.
| File Path | URL | Creates URL? |
|---|---|---|
| app/about.tsx | /about | Yes - flat file creates URL |
| app/contact.tsx | /contact | Yes - flat file creates URL |
| app/blog.tsx | /blog | Yes - flat file creates URL |
| app/page.tsx | / | Yes - root file creates URL |
Basic File Routing
A file in src/app directly maps to a URL. The file must export a default React component.
export default function AboutPage() {
return <h1>About Us</h1>
}export default function ContactPage() {
return <h1>Contact Us</h1>
}page.tsx needed.Flat Files vs Folders
Both achieve the same URL, but file-based is shorter for simple pages.
| Approach | File Path | URL | Creates URL? |
|---|---|---|---|
| File-based | app/about.tsx | /about | Yes - file creates URL |
| Folder-based | app/about/page.tsx | /about | Yes - folder + page creates URL |
| File-based | app/dashboard.tsx | /dashboard | Yes - file creates URL |
| Folder-based | app/dashboard/page.tsx | /dashboard | Yes - folder + page creates URL |
File-based
Folder-based
_components inside the route.Index Files
index.tsx inside a folder maps to that folder's URL. This is file-based routing inside a folder.
| File Path | URL | Creates URL? |
|---|---|---|
| app/dashboard/index.tsx | /dashboard | Yes - index creates URL |
| app/blog/index.tsx | /blog | Yes - index creates URL |
| app/blog/authors/index.tsx | /blog/authors | Yes - nested index creates URL |
index.tsx is equivalent to page.tsx inside that folder - both create the same URL. Choose one pattern and stick to it.File Extensions & Priority
Supported extensions for file-based routes and their priority when the same name exists.
| Extension | Creates URL? | Description |
|---|---|---|
| .tsx | Yes | Highest priority - creates URL |
| .jsx | Yes | Second priority - creates URL if no .tsx |
| .ts | Yes | Third priority |
| .js | Yes | Fourth priority |
| .mdx | Yes | MDX page - creates URL |
| .md | Yes | Markdown page - creates URL |
Reserved Names
These file names are never treated as flat file routes - they are special files for structure, not routes.
| File Name | Creates URL? | Reason |
|---|---|---|
| page.tsx | Yes - but via folder | Special - defines folder route |
| layout.tsx | No | Special file - layout, not route |
| loading.tsx | No | Special file - loading UI |
| error.tsx | No | Special file - error UI |
| not-found.tsx | No | Special file - 404 UI |
| template.tsx | No | Special file - template |
| default.tsx | No | Special file - parallel route fallback |
| global-error.tsx | No | Special file - global error |
about.tsx, contact.tsx create URLs. Reserved names like layout.tsx, loading.tsx, error.tsx do not create URLs - they are special files.Complete Example
File-based routing only - flat files that create URLs without folders.
| File Path | URL | Creates URL? |
|---|---|---|
| app/page.tsx | / | Yes - creates URL |
| app/about.tsx | /about | Yes - file based creates URL |
| app/contact.tsx | /contact | Yes - file based creates URL |
| app/blog.tsx | /blog | Yes - file based creates URL |
| app/dashboard/index.tsx | /dashboard | Yes - index file creates URL |
| app/dashboard/settings.tsx | /dashboard/settings | Yes - nested file creates URL |
| app/layout.tsx | - | No - reserved name, no URL |
| app/_components/Header.tsx | - | No - private folder, no URL |
about.tsx create URLs directly. Folder + page.tsx also creates URLs but is folder-based. Reserved names like layout.tsx never create URLs. Each valid file creates a URL.