#MDX access variable for dynamic props or params from getStaticPaths
1 messages · Page 1 of 1 (latest)
Hey, can you share your setup? Where are you calling getStaticPaths?
I'm calling getStaticPaths in pages/[slug].mdx file. I would like to use slug in my MDX as a variable
@runic storm, any idea? You can't access the Astro global, so is this unsupported?
Oh boy yeah, using [dynamic] routes for MDX wouldn't work well for static sites. We should really warn against that actually...
For SSR, can you get the param?
I'd recommend refactoring this to a pages/[slug].astro file, and splitting out your MDX content to a separate MDX file that receives data as props. Here's a snippet:
---
import Hero from '../components/Hero.mdx'
export function getStaticPaths() {
return [{ params: { slug: 'post-1' } }...]
}
const heading = "My site"
---
<Hero heading={heading} />
And in your MDX file (Hero.mdx in this case) can retrieved props using props. like so:
# {props.heading}
My content!
Well you can't access Astro.params, so probably not. I personally wouldn't use MDX files dynamic routes 🤷♂️