Docs
Defining Routes

Defining Routes

This page will guide you through how to define and organize routes your application with another react router.

Creating Routes

Another react router uses a file-system based router where folders are used to define routes.

Each folder represents a route segment that maps to a URL segment. To create a nested route, you can nest folders inside each other.

Route segments to path segments

A special page.js file is used to make route segments publicly accessible.

Defining Routes

In this example, the /dashboard/analytics URL path is not publicly accessible because it does not have a corresponding page.js file. This folder could be used to store components, stylesheets, images, or other colocated files.

Good to know: .js, .jsx, ts or .tsx file extensions can be used for special files.

Creating UI

Special file conventions are used to create UI for each route segment. The most common are pages to show UI unique to a route, and layouts to show UI that is shared across multiple routes.

For example, to create your first page, add a page.js file inside the routes directory and export a React component:

/src/routes/page.tsx
export default function Page() {
	return <h1>Hello, Next.js!</h1>
}