Next.js layout.tsx vs template.tsx in app router. How to use them?

28 views Asked by At

Lets say we have

/app
   /[testParam]
      layout.tsx
      template.tsx
      page.tsx
...

I expect each of them get the same props

interface Props {
  children: ReactNode;
  params: {
    testParam: string;
  };
}

But template actually doesn't – it gets no params. Why a template never get params, but just a children?

Next.js template docs says "Templates are similar to layouts... But creates a new instance for each of their children on navigation". But it's not similar, it doesn't have access to params. Is it by design? Am i missed some configuration or misunderstood the docs?

Glad for any thoughts on this. Thank you!

0

There are 0 answers