#Blocked on nested routes

1 messages · Page 1 of 1 (latest)

indigo oasis
indigo oasis
#

I tried to implement the ideas described above and ended up with a folder structure like this:

pages
  accounts
    index.tsx
    [accountId]
      holdings.tsx
      orders.tsx

Note that I have not implemented the order-details path yet, but does this look right so far?

The only concern I have is that the deeper I go, the pages are repeating the code from the shallower pages. For example,

  1. /account/index.tsx fetches accounts and renders them in the sidebar.
  2. /account/[accountId]/holdings.tsx also fetches accounts and renders them in the sidebar (in additon to fetching holdings and rendering them).

Is there a better way?

candid wagon
#

you can use client-side perPage layout, the layout loads the data, you simply need to set it up for each page. Did you try that already?

#

I know this part of Next is confusing, but remember that an user can reach each page directly via URL, so they kinda behave as their own, independant website (that's what make Next.js fast). The price to pay is that you need to configure the layout for each page currently, but you can still have 99% of the code reused using either client-side layout, or a reusable helper to implement your getServerSideProps

slender parcel
indigo oasis
#

Thanks for your response @candid wagon. I haven't tried layouts yet, will try it. I don't see any examples of layouts loading data, so the question is if they can have getServerSideProps() of their own. If yes, I can implement the sidebar as a layout, otherwise I will have to make it a regular react component and pass data to it.

#

@slender parcel, I looked at the SO question. I don't think it is related to what I am asking.

candid wagon
#

the "persistent" part is the key here, that's the difference with just adding the layout to page markup

indigo oasis
#

Thank you again for this reference, @candid wagon. The Next docs do not describe what "persistence" means in this context. I was thinking persistence as in component state persistence!!