docs/01-app/03-api-reference/03-file-conventions/template.mdx
A template file is similar to a layout in that it wraps a layout or page. Unlike layouts that persist across routes and maintain state, templates are given a unique key, meaning children Client Components reset their state on navigation.
They are useful when you need to:
useEffect on navigation.A template can be defined by exporting a default React component from a template.js file. The component should accept a children prop.
<Image alt="template.js special file" srcLight="/docs/light/template-special-file.png" srcDark="/docs/dark/template-special-file.png" width="1600" height="444" />
export default function Template({ children }: { children: React.ReactNode }) {
return <div>{children}</div>
}
export default function Template({ children }) {
return <div>{children}</div>
}
In terms of nesting, template.js is rendered between a layout and its children. Here's a simplified output:
<Layout>
<Template key={routeParam}>{children}</Template>
</Layout>
children (required)Template accepts a children prop.
<Layout>
<Template key={routeParam}>{children}</Template>
</Layout>
useEffect will re-synchronize as the component remounts.| Version | Changes |
|---|---|
v13.0.0 | template introduced. |