Dynamic Routing in Nuxt
Set up a catch-all route in the Nuxt project to render new stories dynamically.
Fetch and render a story dynamically
Section titled “Fetch and render a story dynamically”Create a app/pages/[…slug].vue file to fetch all stories in the space.
<script setup>const slug = useRoute().params.slug;
const { story } = await useAsyncStoryblok( slug && slug.length > 0 ? slug.join('/') : 'home', { api: { version: 'draft', }, },);</script>
<template> <StoryblokComponent v-if="story" :blok="story.content" /></template>Get the slug from the current route, making an exception for the home story to be /.
Related resources
Section titled “Related resources”
Thanks! We received your feedback.
An error occurred. Please try again.
Was this page helpful?
This site uses reCAPTCHA and Google's Privacy Policy. Terms of Service apply.
Get in touch with the Storyblok community