vue.js - Gridsome - 如何添加类别 slug 以发布 URL
问题描述
我想将类别 slug 添加到我的博客文章的 URL 中。即:my-website.com/caterory-slug/post-slug
我正在设置这样的路径:
module.exports = {
siteName: 'Gridsome',
siteDescription: 'A WordPress starter for Gridsome',
templates: {
WordPressCategory: '/category/:slug', // adds a route for the "category" post type (Optional)
WordPressPost: [
{
path: (node) => {
return `/${node.categories[0].slug}/${node.slug}`
}
}
]
// WordPressPostTag: '/tag/:slug' // adds a route for the "post_tag" post type (Optional)
},
plugins: [
...
]
}
但是我在类别 slug 的 URL 中未定义。我可以用 ID 替换类别的 slug,它会起作用。类别的 ID 将在 URL 中。我可以在模板中访问类别的 slug,但不能在 URL 中访问。
在同一个模板中,我的图形 ql 查询如下所示:
<page-query>
query Home ($page: Int) {
allWordPressPost (page: $page, perPage: 10) @paginate {
pageInfo {
totalPages
currentPage
}
edges {
node {
id
title
path
excerpt
categories {
slug
}
}
}
}
}
</page-query>
查询的响应是:
"edges": [
{
"node": {
"id": "581",
"title": "Chatbot Lazy Loader Plugin",
"path": "/categories-0-slug/chatbot-lazy-loader-plugin/",
"categories": [
{
"slug": "wordpress"
}
]
}
}...
]
解决方案
推荐阅读
- ios - 如何在 Siri 中为给定的 IntentKit 域设置我的应用程序默认值?
- webpack - 如何修复 html 部分的热重载
- javascript - 有没有办法在 discord.js 中发出 ping 命令?
- node.js - 使用 neon 和 rust 的异步类中的生命周期问题
- amazon-dynamodb - aws cdk 是否允许更新 cloudformation 堆栈中导入的 aws dynamodb 表
- flutter - 无效的日期格式颤振
- django - 使用 django-Nav Bar for django app 的单页应用程序
- xcode - Error-> Reading plist: 无法读取数据,因为它的格式不正确
- python - 检查输入是否为数字
- r - 如何从R中的多个文档中提取多个引号?