2

My nuxtjs app contains page with dynamic url (actually page has two params event-slug and event-id), then in that page's asyncData method, I extract these params from URL and use for axios request. This page opens when I click on one item on list of events (on another events-list page). When I trigger nuxt generate command, I encounter error because these params are not available while generating static pages. Is there any solution?

SOLUTION (in case someone needs it later):

Assume that I have /event/:slug/:id dynamic route in my Nuxt app and need to create route for all events I receive from backend, add this code into nuxt.config.js:

 generate: {
    routes: () => {
 axios.get('endpoint to get list of events')
        .then((response) => {
          // assume we received array of events in response.data
          let events = response.data;
          return events.map((event) => {
          
            // assume that my Nuxt dynamic route is /event/:slug/:id
            return `/event/${event.slug}/${event.id}`
          })
        })
    }
  },
  • nuxt generate dynamic pages - Google search. If you want to generate routes with dynamic params, you need to set an array of dynamic routes. – muka.gergely Apr 02 '19 at 19:51
  • What if list of events changes after nuxt application is loaded? From my understanding, it is not possible to reload nuxt config in runtime. – Andis Jan 17 '20 at 16:03
  • @Andis this is my understanding too. – Simon Jul 15 '20 at 13:05

0 Answers0