How to make Nuxt.js generate static files for dynamic routing

Nuxt.js provides two ways to publish and deploy applications: server-side rendering application deployment and static application deployment

I chose the second. Executing the npm run generate command can be packaged smoothly, but there is a problem

// nuxt.config.js 
const axios = require("axios")

module.exports = {
  generate: {
    routes: function () {
      return axios.get("https://my-api/users")
      .then((res) => {
        return res.data.map((user) => {
          return "/users/" + user.id
        })
      })      
    }
  }
}

unfortunately, I tried, but failed. Now that the project is online, I have changed the code and am forced to use / users?id=1 this way, but it looks very uncomfortable. This is not my original intention. If anyone has encountered this problem, I hope to communicate with me here

.
Nov.11,2021

Hello, little sister. According to the official document, I have no problem. I use the method of callback route. The code is truncated as follows: (one closing bracket is missing)
nuxt.config.js

generate!
npm run generate

Dynamic routes
Dynamic routes



nuxt.config.js
clipboard.png

:

clipboard.png


the file name of a dynamic route (that is, _ id ) is actually a variable that is not unique on Restful-style routes, so logically it should not be packaged as a static file. Even if the contents of this file are packaged in some form, then the id needs to be queried from query or body, so the landlord's way is actually a more reasonable solution.


I have the same problem as you. I know that dynamic routing cannot be statically packaged. But the way given by the official website
is actually through axios.get (' https://my-api/users') is a request and returns an array of all id, similar to: [{id: 1}, {id: 2}.]
feels very uncomfortable if there is a large amount of data. I don't like query passing parameters, but at present, I personally think that if you package it into a static file, it is best to use query.
found this in nuxt.js 's issues: https://github.com/nuxt/nuxt. can refer to
actually give up all the advantages of server rendering with a static package, which is better than not using nuxt. Since server-side rendering is required, of course yarn build

is selected.
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e5999e-4553d.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e5999e-4553d.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?