简体   繁体   English

为什么我的 nuxt static 站点不提供在 Dist 文件夹中找到的 static html 文件?

[英]Why doesn't my nuxt static site serve the static html files found in the Dist folder?

I've created a blog with Nuxt that has dynamic routes for each of my articles (articles/_slug.vue) .我用 Nuxt 创建了一个博客,其中包含我的每篇文章(articles/_slug.vue)的动态路由。 Inside the _slug.vue file I grab markup content from a strapi CMS using asyncData._slug.vue文件中,我使用 asyncData 从strapi CMS 中获取标记内容。

aricles/_slug.vue aricles/_slug.vue

After running nuxt generate followed by nuxt start and navigating to an article page in my browser, when I open the page source I find that there are numerous Js files being imported /_nuxt/{randomNumbers}.js and a single div with an id __nuxt , most likely resembling an SPA format.在运行nuxt generate然后nuxt start并导航到我的浏览器中的文章页面后,当我打开页面源时,我发现有许多 Js 文件正在导入/_nuxt/{randomNumbers}.js和一个 id为 __nuxt的 div ,很可能类似于 SPA 格式。

page source of an article一篇文章的页面来源

This does not occur with my index.vue page as when I view the page source for index.vue all my content is in the HTML.我的 index.vue 页面不会发生这种情况,因为当我查看 index.vue 的页面源时,我的所有内容都在 HTML 中。

Its important that the google crawler is able to index the content on my article pages, so the page source not containing the blog content is not ideal.谷歌爬虫能够索引我的文章页面上的内容很重要,因此不包含博客内容的页面来源并不理想。

What I don't understand is that when I open the dist folder generated by nuxt I find all my articles in subfolders containing HTML files hard coded with my blog content.我不明白的是,当我打开 nuxt 生成的 dist 文件夹时,我发现我的所有文章都在包含 HTML 文件的子文件夹中,这些文件用我的博客内容硬编码。 So I am wondering why isn't nuxt serving these HTML files, and is there a way to do so?所以我想知道为什么 nuxt 不提供这些 HTML 文件,有没有办法这样做?

distFolder文件夹

As far as I know all pages and components go in one component called Nuxt and I think the "__nuxt" element is that.据我所知,所有页面和组件 go 在一个名为 Nuxt 的组件中,我认为“__nuxt”元素就是这样。 By the way using asyncData and 'nuxt generate' won't make your app server-side dynamic because 'nuxt generate' generates a static site and while using 'nuxt generate' all asyncData hooks will be called once.顺便说一句,使用 asyncData 和“nuxt generate”不会使您的应用程序服务器端动态,因为“nuxt generate”会生成一个 static 站点,并且在使用“nuxt generate”时,所有 asyncData 挂钩都将被调用一次。 For the hard coded blog posts I think you should disable Nuxt Crawler in your nuxt.config.js.对于硬编码的博客文章,我认为您应该在 nuxt.config.js 中禁用 Nuxt Crawler。 Nuxt Docs: The Generate Property #Crawler Nuxt Docs:生成属性#Crawler

export default {
  generate: {
    crawler: false
  }
}

It seems as though after hosting the project on Vercel the static behavior works accordingly.似乎在 Vercel 上托管项目后,static 行为相应地起作用。 When testing the website locally (nuxt start) the content isn't pre loaded into the page source it continues to act as a SPA on dynamic routes.在本地测试网站(nuxt start)时,内容不会预加载到页面源中,它继续充当动态路由上的 SPA。 However after deploying to Vercel the blog content can be found in page source.但是,在部署到 Vercel 后,可以在页面源代码中找到博客内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM