[英]Nuxt pre-rendering command fails to generate static routes
With Nuxt set in spa
mode, npm run generate
should automatically generate a html
file for each static route (meaning for each .vue
file present in pages/
folder).将 Nuxt 设置为
spa
模式时, npm run generate
应自动为每个 static 路由生成一个html
文件(意味着pages/
文件夹中存在的每个.vue
文件)。
For me it doesn't.对我来说不是。 It only generates a
200.html
file (I don't understand what this file is for btw), but nothing else, not even index.html
!它只生成一个
200.html
文件(我不明白这个文件是什么意思),但没有别的,甚至没有index.html
!
Any suggestion?有什么建议吗?
Note: strangely enough, I can make the generation of dynamic routes work if I add the code below in my config file, in which case a html
file is generated for each dynamic route, but still no static route and no index.html
...注意:奇怪的是,如果我在我的配置文件中添加下面的代码,我可以使动态路由的生成工作,在这种情况下,为每个动态路由生成一个
html
文件,但仍然没有 static 路由并且没有index.html
.
generate: {
routes: () => axios.get('http://example.com/wp/wp-json/projects/v1/posts')
.then(res => res.data.map((project) => `/project/${project.ID}/${project.post_name}`))
},
Also if I set router to hash
mode, then I get a index.html
file but no static or dynamic routes are generated (the app works though).此外,如果我将路由器设置为
hash
模式,那么我会得到一个index.html
文件,但没有 static 或生成动态路由(该应用程序可以工作)。
I am unable to reproduce this behaviour with a new project created by running npx create-nuxt-app <project-name>
.我无法通过运行
npx create-nuxt-app <project-name>
的新项目重现此行为。 Additionally, I was able to add a new page, in SPA mode, and have it generated by nuxt generate
.此外,我能够在 SPA 模式下添加一个新页面,并由
nuxt generate
它。
Double check your project configuration, make sure you're on the latest version of nuxt, and if the problem persists, include a minimum example that reproduces the issue.仔细检查您的项目配置,确保您使用的是最新版本的 nuxt,如果问题仍然存在,请提供重现问题的最小示例。
As for the 200.html
file, this is the fallback page .至于
200.html
文件,这是后备页面。
When running a SPA it is more idiomatic to use a 200.html, as it's the only file necessary as no other routes are generated.
在运行 SPA 时,使用 200.html 更为惯用,因为它是唯一需要的文件,因为不会生成其他路由。
I can't confirm, but this hints at your issue of no index.html
being generated, since according to this, 200.html
is the only file required in SPA mode.我无法确认,但这暗示了您没有
index.html
正在生成的问题,因为据此, 200.html
是 SPA 模式中唯一需要的文件。
And lastly, is SPA mode what you're really after?最后,SPA 模式是您真正追求的吗? Normally, these apps only have the one HTML file, and it is all rendered client side.
通常,这些应用程序只有一个 HTML 文件,并且都是在客户端渲染的。 It sounds to me that you're after
nuxt generate
with the mode set to universal
, which renders all static routes, and all supplied dynamic routes, for static hosting.在我看来,您正在使用模式设置为
universal
的nuxt generate
之后,它会为 static 托管呈现所有 static 路由和所有提供的动态路由。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.