File Conventions

Special Files

FilePurposeLevel taught
page.tsxUI of a route; makes the route publicBasic
layout.tsxShared UI that wraps child routes, keeps stateBasic
template.tsxLike a layout but re-mounts on every navigationBasic
loading.tsxInstant loading UI (Suspense fallback)Medium
error.tsxError boundary for the segmentMedium
not-found.tsxUI for notFound() and unknown URLsMedium
route.tsAPI endpoint (GET, POST...) instead of a pageMedium
default.tsxFallback for parallel route slotsAdvance
middleware.ts / proxy.tsRuns before requests (project root)Medium

Special Folder Names

PatternMeaningExample URL
[id]Dynamic segment/products/42
[...slug]Catch-all/docs/a/b/c
[[...slug]]Optional catch-all/shop and /shop/a/b
(shop)Route group: organises files, not in the URL/cart
_componentsPrivate folder: never a route—
@modalParallel route slot—

Render Order

<Layout>
  <Template>
    <ErrorBoundary fallback={<Error/>}>       (error.tsx)
      <Suspense fallback={<Loading/>}>        (loading.tsx)
        <ErrorBoundary fallback={<NotFound/>}> (not-found.tsx)
          <Page/>