3

I'm trying to generate page dynamically. After running nuxt generate the page's are successfully created. But loading the page in (with nuxt start) it says that the title is undefined which I send in the payload while generating.
The payload.js exists for every generated page but it won't work for some reason.

Page result: enter image description here

nuxt.config.js

export default {
    target: 'static',

    generate: {
        routes() {
            const routing = [{url: 'page1', title: 'Page 1'}, {url: 'page2', title: 'Page 2'}, {
                url: 'page3',
                title: 'Page 3'
            }];

            return routing.map(route => {
                return {
                    route: route.url,
                    payload: route,
                };
            });
        }
    }
}

pages/_.vue

<template>
    <h1>{{payload.title}}</h1>
</template>

<script>
    export default {
        async asyncData({payload}) {
            return {payload: payload}
        }
    }
</script>

commands:

nuxt generate
nuxt start
Remco KYP
  • 55
  • 7

1 Answers1

0

You will need to run nuxt generate then nuxt serve in order to test the generated routes.

JGR
  • 1
  • 1
  • 2
  • 2
  • 1
    I don't know why it wasn't working, at some point it started working and don't know anymore what I changed. For the commands i'll only use nuxt generate and start it with an apache server. PS. I can try to recreate this error for helping purpose – Remco KYP Dec 07 '20 at 14:22