Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple calls when dynamic routes? #9

Closed
hackuun opened this issue Nov 30, 2017 · 4 comments

Comments

@hackuun
Copy link

commented Nov 30, 2017

Hi. What if I need to make multiple calls to API to generate routes?

routes () {
      return axios.get(`http://example.me/articles/crypto`)
        .then(res => res.data.map(article => '/crypto/' + article.slug))
      return axios.get(`http://example.me/articles/ico`)
        .then(res => res.data.map(article => '/ico/' + article.slug))
    }

This obviously doesn't work. What should I do in such case?

This question is available on Nuxt.js community (#c7)
@NicoPennec

This comment has been minimized.

Copy link
Member

commented Nov 30, 2017

you may merge your requests with axios.all()

eg.

return axios.all([
    axios.get('https://jsonplaceholder.typicode.com/users'),
    axios.get('https://jsonplaceholder.typicode.com/ico')
])
.then(axios.spread((users, ico) => [...users.data, ...ico.data]))
@hackuun

This comment has been minimized.

Copy link
Author

commented Nov 30, 2017

Thanks for response, but I am not sure I following how to use this ES6 features.

return axios.all([
        axios.get('http://example.me/articles/crypto'),
        axios.get('http://example.me/articles/ico')
      ])
        .then(axios.spread((crypto, ico) => [
          ...crypto.data.map(article => '/crypto/' + article.slug)),
          ...ico.data.map(article => '/ico/' + article.slug))
        ]))
@hackuun

This comment has been minimized.

Copy link
Author

commented Nov 30, 2017

Oh, I had extra bracket It's working! Thanks a bunch @NicoPennec for help and this awesome module

@hackuun hackuun closed this Nov 30, 2017

@hackuun

This comment has been minimized.

Copy link
Author

commented Nov 30, 2017

What about my other question, how to use this

{
        url: '/page/2',
        changefreq: 'daily',
        priority: 1,
        lastmodISO: '2017-06-30T13:30:00.000Z'
}

With Dynamic routes? Right now it's assigning only url.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.