What's an ssg-friendly way to pass data from page level to layout level? #9680
Replies: 1 comment
-
If you need this during SSR, I doubt this will work because of the top-down SSR rendering. See e.g. #19258 In Nuxt 3, definePageMeta would be a way to go. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I've decided to carve out title and navbar of my pages to the layout level. They're more or less fixed in place, so it'd be nice to reduce the amount of stuff that gets recreated in DOM when I navigate between pages. The problem is, both title and the navbar contents are dynamic - title reflects the current page's topic, and the navbar contains "previous, next, up" links that depend on the current page's "position" within a specific collection of pages. I've started looking at possible ways to send that data from page to the layout and haven't found a good way to do so.
title
field, set some default value and mutate it from the page. This works, but it creates two immediate problems:beforeCreate
seems like a good place.target: 'static'
I end up with the default title present in the generated HTML page. Looks like all of the vuex stuff is happening on the client side. This is bad, as it'll not show the correct title to any web crawler that doesn't run the JS after crawling.I've had a desperate idea to hijack vue-meta's functionality and stuff all of the data that I need into custom meta fields - but it turns out that this approach will also not work on the server side.
What are my options here then, if I want to keep the title and navbar in the layout but set the data for it in the pages? The complexity of the commonly suggested solutions seems much higher than the complexity of the problem itself ("set the title relevant to the current page").
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions