[英]Why doesn't Nuxt automaticallly generate my static routes?
All I see in /dist
folder upon doing npm run generate
is one 200.html
and a _nuxt
folder with a bunch of other files: no index.html
and no /about
folder for my about
route.在执行npm run generate
时,我在/dist
文件夹中看到的只是一个200.html
和一个带有一堆其他文件的_nuxt
文件夹:没有index.html
/about
myabout 文件夹和about
文件夹。
So Nuxt
didn't generate my static routes and the app doesn't work.所以Nuxt
没有生成我的 static 路由并且该应用程序不起作用。
What am I missing here?我在这里想念什么?
router.js
: router.js
:
import Vue from 'vue'
import Router from 'vue-router'
Vue.use(Router)
export function createRouter () {
return new Router({
mode: 'history',
routes: [
{
path: '/',
component: () => import(/* webpackChunkName: "index" */ '~/pages/index.vue').then(m => m.default || m)
},
{
path: '/about',
component: () => import(/* webpackChunkName: "about" */ '~/pages/about.vue').then(m => m.default || m)
}
]
})
}
nuxt.config.js
: nuxt.config.js
:
export default {
target: 'static',
ssr: true,
components: true,
...
}
EDIT: if I delete router.js
, hence letting Nuxt.js
do its automatic routing thing, then my static routes do get generated, I've just discovered.编辑:如果我删除router.js
,因此让Nuxt.js
做它的自动路由事情,那么我的 static 路由确实会生成,我刚刚发现。 Why does it fail in the presence of router.js
?为什么它在router.js
的存在下失败?
As explained in the docs here: https://nuxtjs.org/docs/2.x/features/file-system-routing#extending-the-router如此处文档中所述: https://nuxtjs.org/docs/2.x/features/file-system-routing#extending-the-router
If you do pass a router.js
file to your Nuxt, it will overwrite your configuration due to the @nuxtjs/router
module.如果您确实将router.js
文件传递给 Nuxt,由于@nuxtjs/router
模块,它将覆盖您的配置。 You need to choose between the 2.您需要在 2 之间进行选择。
I'd still recommend using the Nuxt way and handle it with your files/folders and let the crawler do it's job.我仍然建议使用 Nuxt 方式并使用您的文件/文件夹处理它,并让爬虫完成它的工作。
Otherwise, you could maybe use the keepDefaultRouter
option of the router module.否则,您可以使用路由器模块的keepDefaultRouter
选项。
For my usage, router-extras-module is good enough in terms of features: if you want to make some aliases or renaming.就我的使用而言, router-extras-module在功能方面已经足够好了:如果你想创建一些别名或重命名。 I do recommend it !我推荐它!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.