Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PC×
Skip to content
World desk4 min

How to Structure a Next.js App with the App Router

A practical App Router structure starts with URL segments and shared layout boundaries, not a prescribed folder hierarchy.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Organize a Next.js App Router project around URL segments and shared UI boundaries: put route files in app/ (or src/app/), use page.tsx to expose a route, and add layout.tsx wherever a subtree needs a persistent shared shell. Keep route-specific implementation close to its route; move code into shared folders only when it is genuinely reused.

A practical starting structure

This example separates route files from reusable project code without imposing a framework-mandated architecture:

As an Amazon Associate I earn from qualifying purchases.

src/
  app/
    layout.tsx            # required root layout
    page.tsx              # /
    blog/
      page.tsx            # /blog
      [slug]/
        page.tsx          # /blog/:slug
    (account)/
      account/
        page.tsx          # /account
    ui/                    # route-oriented implementation, if useful
  components/              # components shared across routes
  lib/                     # data access and utilities
public/                    # static assets

The tree is illustrative, not a required Next.js architecture. The App Router can live in a root-level app/ or in src/app/; src is optional. Choose the latter if keeping application source separate from root-level configuration helps your team. Avoid adding folder layers just to make every project look uniform. See the Next.js project structure documentation.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How folders become routes

Folders inside app/ define route segments, but a folder by itself does not publish a page. A page.tsx file provides the UI for a route; a route segment needs a page or route handler to become publicly accessible. Other files can sit alongside these route files without automatically becoming routes. The file-system routing model and conventions are documented in the Next.js layouts and pages guide.

  • app/page.tsx serves the root path, /.
  • app/blog/page.tsx serves /blog.
  • app/blog/[slug]/page.tsx uses a dynamic segment for paths such as /blog/hello-world.

For current App Router conventions, dynamic route parameters are exposed to pages as a Promise. Follow the current page file reference for the version installed in your project rather than copying older examples that treat params as synchronous.

Put shared interface in layouts

A layout.tsx wraps the pages and nested layouts beneath its segment. Put shared navigation, a section shell, or other interface that should persist across those routes in the layout at their nearest common segment. Layouts preserve state and remain interactive during navigation, making them a useful boundary for UI shared by a subtree—not a place to duplicate route-specific page content. The layouts and pages guide explains their role.

The root layout

Every App Router application requires a root layout. It must render the document’s <html> and <body> elements. Use Next.js’s Metadata API for document metadata rather than manually adding a <head> in the root layout; see the layout file reference.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Nested layouts

If, for example, blog pages share a section navigation that the rest of the site does not, put a layout in app/blog/. The root layout still wraps that section, while the blog layout supplies the additional shared UI. Add a nested layout when a real shared boundary exists; a layout for every folder adds structure without necessarily adding value.

Use route groups to organize without changing URLs

A parenthesized folder such as (marketing) or (dashboard) is a route group: it helps organize related routes and can scope a layout, but its name is omitted from the URL. For example, app/(account)/account/page.tsx maps to /account, not /(account)/account.

Groups are useful when routes belong to a site section, concern, or team but should not gain another URL segment. Check that grouped routes do not resolve to duplicate paths: different route groups cannot define the same URL. Multiple root layouts are supported, but navigating between routes with different root layouts triggers a full page load. That navigation behavior is an important trade-off, so do not split an application into separate root layouts casually. These rules are covered in the route groups reference.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Keep implementation close to its route, then share deliberately

A route is easier to understand and refactor when its unique UI and supporting code are near its page. Components used by several routes can live in a shared components/ directory; data access and utilities can live in lib/ if that separation helps. These are organizational choices, not required Next.js layers. Promote code to a shared location when reuse or ownership actually calls for it, rather than creating a broad hierarchy in advance.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Detailed colocation guidance in the Next.js documentation retrieved for this topic is labeled for Next.js 14 and dated January 2024. Exact file conventions can evolve, so check the documentation for the version your project uses before relying on version-specific behavior. The current project structure reference provides the broader directory conventions.

Choose a structure by testing the boundaries

  • URL clarity: Do folder names produce the paths users should visit?
  • Shared UI: Which routes genuinely share navigation, a shell, or persistent state? Put that UI at their nearest common layout.
  • Ownership: Does the route arrangement match how your team owns features or sections?
  • Refactoring: Can a feature move without forcing unrelated routes to move with it?
  • Navigation: Will users cross between different root layouts and incur a full page load?
  • Conflicts: Could two route groups resolve to the same public path?

For readers new to Next.js, the official getting-started material assumes familiarity with HTML, CSS, JavaScript, and React. It points learners who need a refresher to React Foundations and Next.js Foundations in its getting-started guide.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.