前端笔记(13)nuxt js sitemap.xmpl配置
作者: 图恩分类: 编程开发阅读: 1947发布时间: 2020-08-20 23:34:41
sitemap.xml
通过@nuxtjs/sitemap模块根据前端路由自动生成。
./config/sitemap.js
sitemap路由列表
// sitemap列表配置
export const routes = [ '/:lang', '/:lang/about', '/:lang/parent', '/:lang/parent/about', '/test']
nuxt.config.js
sitemap.xml生成配置,生成多语言的网站地图
// 动态生成sitemap.xml
sitemap: {
// options
gzip: true,
defaults: {
changefreq: 'daily',
priority: 1,
lastmod: new Date()
},
routes: () => {
const list = [] // 根据当前所支持语言locales生成对应的路由
//
locales = ['zh-cn','en-us','zh-hk'] sitemapRoutes.forEach((route) => {
if (route.includes(':lang') > -1) { locales.forEach((local) => { list.push(route.replace(':lang', local))
})
} else {
list.push(route)
}
})
return list
}
},
发表评论 (审核通过后显示评论):