Book a Free Call

Generate static Storyblok site with dynamic pages (Nuxt.js)

Heyo – so got stuck on this one last night and thought I would share.

When generating a site that takes content from Storyblok in Nuxt, I noticed initially that the pages weren’t being built out. I had run into this with Gatsby/GraphCMS before, and it makes sense. The framework (Gatsby or Nuxt or whatever) needs to know what pages you have before it can generate them and fill them with your content.

Anywho, I looked at the docs and they initially didn’t work, so I thought I would share how I got it working here:

Before I added this, I made sure I had installed axios. So I ran yarn add @nuxtjs/axios

Here’s my nuxt.config.js

export default {

  target: 'static',

  head: {
    title: 'Site name',
    htmlAttrs: {
      lang: 'en'
    meta: [
      { charset: 'utf-8' },
      { name: 'viewport', content: 'width=device-width, initial-scale=1' },
      { hid: 'description', name: 'description', content: '' },
      { name: 'format-detection', content: 'telephone=no' }
    link: [
      { rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }

  css: [

  plugins: [

  components: true,

  buildModules: [

  // Modules: here's where I you add your modules for storyblok and axio
  modules: [
  '@nuxtjs/axios',    //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< add axios module in here
        accessToken: 'YOUR STORYBLOK TOKEN GOES HERE',
        cacheProvider: 'memory'

//some options for axios go here if you have them
axios: {
    // extra config e.g
    // BaseURL: 'https://link-to-API'

  build: {

//what follows is the generate function from the docs. But change where axios is called! Otherwise it cries when you generate...

generate: {
  routes: function (callback) {
    const axios = require('axios'); //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< add this in here
    const per_page = 10
    const version = 'published'
    let cache_version = 0
    let page = 1
    // other routes that are not in Storyblok with their slug.
    let routes = ['/'] // adds home directly but with / instead of /home
    // Load space and receive latest cache version key to improve performance
    axios.get(`${token}`).then((space_res) => {
      // timestamp of latest publish
      cache_version =
      // Call first Page of the Stories
      axios.get(`${token}&version=${version}&per_page=${per_page}&page=${page}&cv=${cache_version}`).then((res) => {
 => {
          if (story.full_slug != 'home') {
            routes.push('/' + story.full_slug)
        // Check if there are more pages available otherwise execute callback with current routes.
        const total =
        const maxPage = Math.ceil(total / per_page)
        if (maxPage <= 1) {
          callback(null, routes)
        // Since we know the total we now can pregenerate all requests we need to get all stories
        let contentRequests = []
        for (let page = 2; page <= maxPage; page++) {
        // Axios allows us to exectue all requests using axios.spread we will than generate our routes and execute the callback
        axios.all(contentRequests).then(axios.spread((...responses) => {
          responses.forEach((response) => {
   => {
              if (story.full_slug != 'home') {
                routes.push('/' + story.full_slug)
          callback(null, routes)


Hope that helps someone!

Need rapid website development:

For smaller projects at high speed

Get an instant quote
  • WordPress Super-admin hack

    Read More
  • Add content or ACF field under thumbnail/image gallery in Woocommerce

    Read More
  • Nuxt view localhost on device over WiFi (IP)

    Read More
  • AIO WP Migration: Import stuck on “done preparing blogs” or “done preparing plugins”

    Read More
  • Nuxt Ecommerce (Snipcart/Stripe)

    Read More



Charlie's Cottage, Carrigrohane, Co. Cork, T12 WY9H

(085) 7686677