GitHubnpm

File Conventions

Special filenames and exports that Juice recognizes in the app/routes/directory.

File Conventions

FilenamePurposeReceives
layout.tsxWraps all routes in the current directory and subdirectories. Chains root to leaf.{ children, request }
middleware.tsRuns before all routes in the current directory. Onion model.(req, next)
loading.tsxSuspense fallback for routes in the current directory.No props
error.tsxError boundary fallback for routes in the current directory.{ error }
home.tsxIndex route for the current directory (/).Standard page props
[param].tsxDynamic route segment. The bracket name becomes a typed param.Standard page props
global.cssGlobal stylesheet. Import from layout to apply site-wide.n/a

Export Conventions

These named exports are recognized on route files (.tsx and .ts).

ExportTypeDescription
defaultReact componentThe page component. Rendered as a React Server Component by default.
response{ head?, headers?, boundary? }Unified response configuration. Preferred over individual exports.
response.head{ title?, description? }Metadata injected into the HTML head.
response.headersRecord<string, string> | (req) => Record<string, string>Custom response headers. Can be static or a function of the request.
response.boundaryboolean | 'shell'Per-route streaming mode override.
headersRecord<string, string>Legacy: custom response headers. Use response.headers instead.
metadata{ title?, description? }Legacy: page metadata. Use response.head instead.
prerenderbooleanWhen true, sets immutable cache headers on the response.
GET(req: Request) => ResponseHTTP GET handler. Route acts as an API endpoint.
POST(req: Request) => ResponseHTTP POST handler.
PUT(req: Request) => ResponseHTTP PUT handler.
DELETE(req: Request) => ResponseHTTP DELETE handler.

Directory Structure Example

app/
  routes/
    layout.tsx           # Root layout (wraps everything)
    global.css           # Global styles
    home.tsx             # / route
    middleware.ts        # Root middleware
    about.tsx            # /about route
    blog/
      layout.tsx         # Blog layout (nested)
      loading.tsx        # Blog suspense fallback
      index.tsx          # /blog route
      [slug].tsx         # /blog/:slug route
    admin/
      middleware.ts      # Auth middleware
      layout.tsx         # Admin layout
      dashboard.tsx      # /admin/dashboard route
      error.tsx          # Admin error boundary
    api/
      middleware.ts      # CORS middleware
      health.ts          # /api/health (GET handler)
      users.ts           # /api/users (GET, POST handlers)
  components/
    counter.tsx          # 'use client' component