DocsPluginsShowcaseReleases
npmStar us on GitHub

Getting Started

IntroductionInstallationProject StructureLayouts and PagesLinking and Navigating

Routing

Folder-Based RoutingFile-Based RoutingDynamic RoutesParallel RoutesIntercepting RoutesCatch-All RoutesMDX & Markdown Pages

Special Files

Loading UIError BoundariesTemplateDefaultNot Found

Data Fetching

LoadersActionsAccessing Route Data

Metadata

Metadata & SEOOpen Graph & TwitterIcons & Favicons

API Routes

API Routes OverviewPlain Function HandlersHono IntegrationDynamic API Routes

Environment Variables

OverviewPrefixes & Client ExposureUsing in API Routes

Styling

CSS OverviewTailwind CSSCSS Modules

Platforms

WebWindowsmacOSLinuxAndroidiOS

Deployment

Deployment OverviewProduction ServerStatic ExportHosting Providers

A native React framework for building cross-platform applications from a single codebase.

Resources

  • Documentation
  • Plugins
  • Showcase
  • Releases

Community

  • GitHub Discussions
  • Reddit
  • Discord
  • LinkedIn

More

  • npm
  • GitHub
  • Issues
  • License

© 2026 Bini Cooperation.

Template

Experimental

template.tsx wraps pages inside the layout chain - special file, no URL, nearest-wins.

Overview

A template.tsx file wraps each page inside the layout chain. Like layout.tsx, it is a special file and does not create a URL. Unlike a layout, it is resolved per page scope and is a good place for effects that should run when navigating between pages.

app
layout.tsx
template.tsx
page.tsx
about
page.tsx
/
/about
FileRole
layout.tsxWraps segment + children, receives params
template.tsxWraps page inside layout chain, receives children
page.tsxRoute content
A template only applies to routes inside the folder that declares it and its descendants. The nearest usable template wins, and templates receive children only - not params.

Templates vs Layouts

Both are special files that wrap page content without creating a URL. They differ in what they receive and in how they behave on navigation.

Featurelayout.tsxtemplate.tsx
WrapsSegment + all childrenPage inside layout chain
Propsparams + children (Outlet)children only
Typical useNav, sidebar, shared chromePage-level effects, transitions
State persistencePersists across navigationResets on every navigation
app
layout.tsx
template.tsx
page.tsx
about
layout.tsx
template.tsx
page.tsx
/
/about

In practice, put persistent chrome - navigation bars, sidebars, footers - in a layout.tsx. Put anything that should re-run or reset when the route changes in a template.tsx.

src/app/layout.tsx
import { Outlet } from 'react-router-dom'

export default function RootLayout() {
  return (
    <div>
      <nav>Persistent nav</nav>
      <Outlet />
    </div>
  )
}
src/app/template.tsx
import { useEffect } from 'react'

export default function RootTemplate({
  children,
}: {
  children: React.ReactNode
}) {
  useEffect(() => {
    // Runs once per page view
    console.log('Page mounted')
  }, [])

  return <>{children}</>
}

Creating a Template

Create template.tsx in any folder. It must have a default export and receives children.

src/app/template.tsx
export default function Template({
  children,
}: {
  children: React.ReactNode
}) {
  return <div>{children}</div>
}

Because templates are unmounted and remounted on navigation, they are useful for running effects once per page view:

src/app/template.tsx
import { useEffect } from 'react'

export default function Template({
  children,
}: {
  children: React.ReactNode
}) {
  useEffect(() => {
    // Useful for analytics or focus management
    console.log('Template active')
  }, [])

  return <div>{children}</div>
}
Templates that contain an html element are ignored, the same way layouts are. Prefer simple wrappers around children.

Use Cases

Prefer a template when you need page-scoped behavior without changing the persistent layout chrome.

Use CaseWhy template?
Page transitionsWrap the page for enter/exit animation classes
Analytics / loggingRun effects on every page view
Focus managementMove focus when the page content changes
Reset local UI stateKeep layout state, but re-initialize page-level UI on navigation

Complete Example

Templates next to layouts, loading, and error. Special files do not create URLs.

app
layout.tsx
template.tsx
loading.tsx
error.tsx
page.tsx
dashboard
layout.tsx
template.tsx
page.tsx
settings
page.tsx
/
/dashboard
/dashboard/settings
FilePurpose
src/app/layout.tsxRoot layout
src/app/template.tsxRoot template
src/app/page.tsxHome page
src/app/dashboard/template.tsxDashboard page wrapper
src/app/dashboard/page.tsxDashboard page
Use layout.tsx for shared chrome. Use template.tsx for page-level wrapping inside that chrome.

Error Boundaries

Catch render errors and show a fallback UI.

Default

Fallback for a parallel route slot with no match.

Loading UI

Show a fallback while pages and layouts load.

Layouts and Pages

Create your first pages and wrap them in shared layouts.

Folder-Based Routing

Define routes with folders and page files inside them.

Static Export

How every route is pre-rendered to HTML at build time.

Was this helpful?
PreviousError Boundaries
NextDefault

On this page

  • Overview
  • Templates vs Layouts
  • Creating a Template
  • Use Cases
  • Complete Example
Edit this page on GitHub

Template

Experimental

template.tsx wraps pages inside the layout chain - special file, no URL, nearest-wins.

Overview

A template.tsx file wraps each page inside the layout chain. Like layout.tsx, it is a special file and does not create a URL. Unlike a layout, it is resolved per page scope and is a good place for effects that should run when navigating between pages.

app
layout.tsx
template.tsx
page.tsx
about
page.tsx
/
/about
FileRole
layout.tsxWraps segment + children, receives params
template.tsxWraps page inside layout chain, receives children
page.tsxRoute content
A template only applies to routes inside the folder that declares it and its descendants. The nearest usable template wins, and templates receive children only - not params.

Templates vs Layouts

Both are special files that wrap page content without creating a URL. They differ in what they receive and in how they behave on navigation.

Featurelayout.tsxtemplate.tsx
WrapsSegment + all childrenPage inside layout chain
Propsparams + children (Outlet)children only
Typical useNav, sidebar, shared chromePage-level effects, transitions
State persistencePersists across navigationResets on every navigation
app
layout.tsx
template.tsx
page.tsx
about
layout.tsx
template.tsx
page.tsx
/
/about

In practice, put persistent chrome - navigation bars, sidebars, footers - in a layout.tsx. Put anything that should re-run or reset when the route changes in a template.tsx.

src/app/layout.tsx
import { Outlet } from 'react-router-dom'

export default function RootLayout() {
  return (
    <div>
      <nav>Persistent nav</nav>
      <Outlet />
    </div>
  )
}
src/app/template.tsx
import { useEffect } from 'react'

export default function RootTemplate({
  children,
}: {
  children: React.ReactNode
}) {
  useEffect(() => {
    // Runs once per page view
    console.log('Page mounted')
  }, [])

  return <>{children}</>
}

Creating a Template

Create template.tsx in any folder. It must have a default export and receives children.

src/app/template.tsx
export default function Template({
  children,
}: {
  children: React.ReactNode
}) {
  return <div>{children}</div>
}

Because templates are unmounted and remounted on navigation, they are useful for running effects once per page view:

src/app/template.tsx
import { useEffect } from 'react'

export default function Template({
  children,
}: {
  children: React.ReactNode
}) {
  useEffect(() => {
    // Useful for analytics or focus management
    console.log('Template active')
  }, [])

  return <div>{children}</div>
}
Templates that contain an html element are ignored, the same way layouts are. Prefer simple wrappers around children.

Use Cases

Prefer a template when you need page-scoped behavior without changing the persistent layout chrome.

Use CaseWhy template?
Page transitionsWrap the page for enter/exit animation classes
Analytics / loggingRun effects on every page view
Focus managementMove focus when the page content changes
Reset local UI stateKeep layout state, but re-initialize page-level UI on navigation

Complete Example

Templates next to layouts, loading, and error. Special files do not create URLs.

app
layout.tsx
template.tsx
loading.tsx
error.tsx
page.tsx
dashboard
layout.tsx
template.tsx
page.tsx
settings
page.tsx
/
/dashboard
/dashboard/settings
FilePurpose
src/app/layout.tsxRoot layout
src/app/template.tsxRoot template
src/app/page.tsxHome page
src/app/dashboard/template.tsxDashboard page wrapper
src/app/dashboard/page.tsxDashboard page
Use layout.tsx for shared chrome. Use template.tsx for page-level wrapping inside that chrome.

Error Boundaries

Catch render errors and show a fallback UI.

Default

Fallback for a parallel route slot with no match.

Loading UI

Show a fallback while pages and layouts load.

Layouts and Pages

Create your first pages and wrap them in shared layouts.

Folder-Based Routing

Define routes with folders and page files inside them.

Static Export

How every route is pre-rendered to HTML at build time.

Was this helpful?
PreviousError Boundaries
NextDefault

On this page

  • Overview
  • Templates vs Layouts
  • Creating a Template
  • Use Cases
  • Complete Example
Edit this page on GitHub