Uses file-system based routing, meaning you can use folders and files to define routes. This page will guide you through how to create layouts and pages, and link between them.
A page is UI that is rendered on a specific route. To create a page, add a page file inside the app directory and default export a React component. For example, to create an index page (/):
A layout is UI that is shared between multiple pages. On navigation, layouts preserve state, remain interactive, and do not rerender.
You can define a layout by default exporting a React component from a layout file. The component renders an <Outlet />, which is where the child page or nested layout is mounted. The layout in app/layout.tsx is called the root layout. It is defined at the root of the app directory and wraps all routes.
<html> inside a layout. A layout that returns an <html> element is excluded from the chain. To set attributes on <html> or <body>, use the document export.A nested route is a route composed of multiple URL segments. For example, the /blog/[slug] route is composed of three segments:
/ (Root Segment)blog (Segment)[slug] (Leaf Segment)page and layout) are used to create UI that is shown for a segment.To create nested routes, you can nest folders inside each other. For example, to add a route for /blog, create a folder called blog in the app directory:
You can continue nesting folders to create nested routes. For example, to create a route for a specific blog post, create a new [slug] folder inside blog and add a page file:
By default, layouts in the folder hierarchy are also nested, which means they wrap child layouts through their <Outlet />. You can nest layouts by adding layout inside specific route segments (folders).
If you were to combine the two layouts above, the root layout (app/layout.tsx) would wrap the blog layout (app/blog/layout.tsx), which would wrap the blog (app/blog/page.tsx) and blog post page (app/blog/[slug]/page.tsx).
Dynamic segments allow you to create routes that are generated from data. For example, instead of manually creating a route for each individual blog post, you can create a dynamic segment to generate the routes based on blog post data.
To create a dynamic segment, wrap the segment (folder) name in square brackets: [segmentName]. For example, in the app/blog/[slug]/page.tsx route, the [slug] is the dynamic segment.
useParams() (auto-imported). Supports [slug], [...slug] catch-all, and [[...slug]] optional catch-all.You can access search parameters using the useSearchParams hook. It is auto-imported in all pages.
useSearchParams when you need search params to load data (pagination, filtering from API).useSearchParams with client filtering (filtering a list already loaded).new URLSearchParams(window.location.search) in callbacks to read without re-renders.You can use the <Link> component to navigate between routes. <Link> is a built-in component that extends the HTML <a> tag to provide client-side navigation without full page reloads.
For example, to generate a list of blog posts, import <Link> (auto-imported) and pass a to prop:
While <Link> is ideal for declarative navigation in your JSX, sometimes you need to navigate programmatically. Bini.js provides the useNavigate hook for this.
Unlike <Link>, which renders an anchor tag, useNavigate returns a function you can call inside event handlers, effects, or after async operations. It performs a client-side navigation without a full page reload, preserving layout state and scroll position just like <Link>. This is perfect for post-form redirects, authentication flows, or conditional navigation where you need logic before navigating.
Define routes from the filesystem with folder-based and file-based conventions.
Navigate between routes with Link, useNavigate, and prefetching.
Show a fallback while pages and layouts load.
Catch render errors and show a fallback UI.
Fetch data before a route renders.
Add backend endpoints with plain functions or a full Hono app.
Uses file-system based routing, meaning you can use folders and files to define routes. This page will guide you through how to create layouts and pages, and link between them.
A page is UI that is rendered on a specific route. To create a page, add a page file inside the app directory and default export a React component. For example, to create an index page (/):
A layout is UI that is shared between multiple pages. On navigation, layouts preserve state, remain interactive, and do not rerender.
You can define a layout by default exporting a React component from a layout file. The component renders an <Outlet />, which is where the child page or nested layout is mounted. The layout in app/layout.tsx is called the root layout. It is defined at the root of the app directory and wraps all routes.
<html> inside a layout. A layout that returns an <html> element is excluded from the chain. To set attributes on <html> or <body>, use the document export.A nested route is a route composed of multiple URL segments. For example, the /blog/[slug] route is composed of three segments:
/ (Root Segment)blog (Segment)[slug] (Leaf Segment)page and layout) are used to create UI that is shown for a segment.To create nested routes, you can nest folders inside each other. For example, to add a route for /blog, create a folder called blog in the app directory:
You can continue nesting folders to create nested routes. For example, to create a route for a specific blog post, create a new [slug] folder inside blog and add a page file:
By default, layouts in the folder hierarchy are also nested, which means they wrap child layouts through their <Outlet />. You can nest layouts by adding layout inside specific route segments (folders).
If you were to combine the two layouts above, the root layout (app/layout.tsx) would wrap the blog layout (app/blog/layout.tsx), which would wrap the blog (app/blog/page.tsx) and blog post page (app/blog/[slug]/page.tsx).
Dynamic segments allow you to create routes that are generated from data. For example, instead of manually creating a route for each individual blog post, you can create a dynamic segment to generate the routes based on blog post data.
To create a dynamic segment, wrap the segment (folder) name in square brackets: [segmentName]. For example, in the app/blog/[slug]/page.tsx route, the [slug] is the dynamic segment.
useParams() (auto-imported). Supports [slug], [...slug] catch-all, and [[...slug]] optional catch-all.You can access search parameters using the useSearchParams hook. It is auto-imported in all pages.
useSearchParams when you need search params to load data (pagination, filtering from API).useSearchParams with client filtering (filtering a list already loaded).new URLSearchParams(window.location.search) in callbacks to read without re-renders.You can use the <Link> component to navigate between routes. <Link> is a built-in component that extends the HTML <a> tag to provide client-side navigation without full page reloads.
For example, to generate a list of blog posts, import <Link> (auto-imported) and pass a to prop:
While <Link> is ideal for declarative navigation in your JSX, sometimes you need to navigate programmatically. Bini.js provides the useNavigate hook for this.
Unlike <Link>, which renders an anchor tag, useNavigate returns a function you can call inside event handlers, effects, or after async operations. It performs a client-side navigation without a full page reload, preserving layout state and scroll position just like <Link>. This is perfect for post-form redirects, authentication flows, or conditional navigation where you need logic before navigating.
Define routes from the filesystem with folder-based and file-based conventions.
Navigate between routes with Link, useNavigate, and prefetching.
Show a fallback while pages and layouts load.
Catch render errors and show a fallback UI.
Fetch data before a route renders.
Add backend endpoints with plain functions or a full Hono app.