Best way to retrieve frontmatter from the next page #4831
-
| 
         I'm looking to assess the frontmatter of an incoming page using the  Additionally, if you know a method to load the HTML content of the next page, that would be very helpful! Thank you very much in advance  | 
  
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
| 
         Hmm page is loaded after route change. So, hard to get it that way. Maybe you can extract the relevant data to a separate file (maybe createContentLoader) and do something like this: // .vitepress/theme/index.ts
import type { Theme } from 'vitepress'
import DefaultTheme from 'vitepress/theme'
import { data } from '../../frontmatter.data.js'
export default {
  extends: DefaultTheme,
  enhanceApp({ router }) {
    router.onBeforeRouteChange = (to) => {
     const frontmatter = data[to]
    }
  }
} satisfies Theme | 
  
Beta Was this translation helpful? Give feedback.
Hmm page is loaded after route change. So, hard to get it that way. Maybe you can extract the relevant data to a separate file (maybe createContentLoader) and do something like this: