Deviopath › Next.js

Route From a Page File

Easy · Routing

The App Router uses folders to define routes: a folder inside app/ becomes a URL segment, and a page file inside it makes that route public. So app/blog/page.tsx is the page for /blog, and app/page.tsx is the home page /.

Write routeFromFile(filePath) that returns the URL for a page file, or null when the file is not a page file.

- Paths always start with app/.

- A page file is named page with one of the extensions .js, .jsx, .ts, .tsx.

- Keep every folder name as it is (dynamic folders like [slug] stay unchanged).

Next: Special File Names