vike icon indicating copy to clipboard operation
vike copied to clipboard

Nested Layouts

Open brillout opened this issue 2 years ago • 4 comments

This should be fairly easy to implement; comment here if you need this and this will be implemented (ETA within a week).

The idea is to export const isNested = true in .page.route.js.

/pages/product/@id/index.page.js

/pages/product/@id/reviews.page.js
/pages/product/@id/reviews.page.route.js

/pages/product/@id/pricing.page.js
/pages/product/@id/pricing.page.route.js
// /pages/product/@id/reviews.page.route.js
export const isNested = true
// /pages/product/@id/pricing.page.route.js
export const isNested = true
// /pages/product/@id/index.page.js

// The parent page
export function Page() {
  const pageContext = usePageContext()
  const { Page: NestedView } = pageContext.nested[0]
  // ...
}

The onBeforeRender() hooks of all .page.js matching the same URL are called in parallel.

The parent onBeforeRender() hooks are cached if the URL segment didn't change for the parent .page.js.

brillout avatar Jun 21 '22 12:06 brillout

This feature would be great to use in my current project. Currently, using the solution given here. Thank you!

Jearce avatar Jul 25 '22 21:07 Jearce

@Jearce Thanks for the comment! I'm busy with high prio things at the moment (e.g. bug/design fixes), but let me know if/when the current situation is getting too annoying for you. I'll then implement this.

brillout avatar Jul 26 '22 10:07 brillout

+1 to this DX enhancement and parallel onBeforeRender() calls. Working on a project using the solution in the docs like @Jearce, but would still be a nice feature. Thanks!

taylorfsteele avatar Sep 03 '22 21:09 taylorfsteele

FYI I'm still thinking about this. The design I will come up with may be quite different from what others are doing. Stay tuned.

For (other) readers: feel free to further push for this by adding a comment here.

brillout avatar Sep 05 '22 13:09 brillout

The overall design is starting to crystalize.

The Single Route File design will play a central role here.

Stay tuned.

As always, if this is urgent for someone, then definitely let me know!

brillout avatar Oct 05 '22 11:10 brillout

(I follow your request to comment, as I'm interested as well 😉)

Switching to something-not-React + vite-plugin-ssr, and coming from Remix, I can tell you a nested layout feature would be appreciated ;)

binajmen avatar Oct 28 '22 18:10 binajmen

I'm in the same boat, was missing Vite, or at least more configurability with Remix and React alternatives.

vite-plugin-ssr is definitely amazing though also missing some of Remix's simplicity 😇

CanRau avatar Oct 28 '22 18:10 CanRau

For folks who need/want improved Nested Layouts, please PM on discord.

brillout avatar Oct 29 '22 17:10 brillout

I want to use this feature. What should I do?

MrQinYQ avatar Nov 22 '22 11:11 MrQinYQ

PM on discord

brillout avatar Nov 22 '22 23:11 brillout

The state of Page should be preserved on navigation to a sibling route. If it's a navigation to a sibling route, only swap out the pageContext.nested[0] in the context, don't run the client-side render entry.

nitedani avatar Dec 17 '22 20:12 nitedani

Yes the pageContext is preserved, but the onBeforeRender() of the nested view is (re-)run and the whole page's onRenderClient (the upcoming new name for the client-side render() hook) is re-run.

brillout avatar Dec 17 '22 22:12 brillout

Also interested – nested views using the render() solution is working but bad DX.

lutzissler avatar Feb 08 '23 19:02 lutzissler

This feature would simplify a lot of things in my projects ;) Looking forward for it.

rossanmol avatar May 09 '23 12:05 rossanmol

Also interested – nested views using the render() solution is working but bad DX.

This feature would simplify a lot of things in my projects ;) Looking forward for it.

Thanks for the push.

FYI it's slowy but surely creeping towards the top of the TODO list.

Sponsoring much welcome to give it a signficant bump to the top.

And, as always, feel free to let me know and elaborte when the workaround becomes painful. That definitely makes a difference in priority as well.

brillout avatar May 09 '23 15:05 brillout

Sound like a good idea to have this DX. Please support if possible. Thanks!

pencilcheck avatar Oct 29 '23 09:10 pencilcheck

Closing in favor of improved docs https://vike.dev/Layout#nested-layouts and upcoming uproved DX https://github.com/vikejs/vike/issues/1459 (including deep integration with data fetching tools).

brillout avatar Jan 27 '24 10:01 brillout