Next.js Discord

Discord Forum

layout.tsx for pages

Answered
Say's Phoebe posted this in #help-forum
Open in Discord
Say's PhoebeOP
I am in the pages dir and the layout from app dir is not applying to the pages, how to fix this?
Answered by averydelusionalperson
but you can directly fetch inside the component
View full answer

34 Replies

it is not supposed to be
app dir & pages dir are different
Say's PhoebeOP
any fix?
Say's PhoebeOP
for applying the same layout to pages
write the same code as you wrote in app dir?
it shouldn't be much
like just a header or sidebar
Say's PhoebeOP
But just from switching from / to /themes route, it is reloading the entire same thing
even when using next/link
I get it, is there a way to put index page inside pages?
then everything will be fixed
I think I just need to put page.tsx inside pages
nvm
you can
I don't understand your problem at all
@averydelusionalperson wdym by index page?
Say's PhoebeOP
the / route
pages/index.js?
@averydelusionalperson `pages/index.js`?
Say's PhoebeOP
ok, let me explain this simply:

- The app dir has the page.tsx which takes the layout from layout.tsx
- I have a landing_page.tsx in the pages dir
- I want to apply the same layout from layout.tsx to landing_page.tsx
how to do this?
you can't, write the logic you wrote in app/layout.tsx file in the pages/_app.tsx layout
Say's PhoebeOP
yes, if I do this, the entire page reloads when moving from route page.tsx to landing_page.tsx, I don't want to reload the entire navbar/footer
well, then have landing_page in app dir itself
@averydelusionalperson well, then have landing_page in app dir itself
Say's PhoebeOP
but then I can't do ssr
why can't you?
Say's PhoebeOP
Error: you can't use getserversideprops() in app/
some kind of error like this
yes, you can't have getServerSideProps in app dir
but you can directly fetch inside the component
Answer
Say's PhoebeOP
oh! thanks a lot!