Next.js · Junior · Question 43 of 75
How does template.tsx differ from layout.tsx?
- ✓Correct answer: A template remounts on every navigation, a layout persists
- 2A template renders only on the server, a layout only on the client
- 3A template is used only for email templates
Explanation
A template wraps pages like a layout but gets a unique key on each navigation: state resets and effects run again. This is useful, for example, for enter animations or logging page views. In most cases a layout is enough.