经过一些调查,我发现使用gatsby-plugin-create-client-paths有一种更简单的方法。您需要做的就是使用yarn或安装它,npm然后在其中gatsby-config.js添加以下内容:
{
resolve: `gatsby-plugin-create-client-paths`,
options: { prefixes: [`/articles/*`] },
},Run Code Online (Sandbox Code Playgroud)
这意味着每个请求 slug 像这样:/articles/the-slug将请求articles.js页面并使用LinkGatsby 提供的页面,您可以state像这样通过props传递 props :
<Link to="/articles/the-slug" state={{ slug: "the-slug", ...etc }}>Anchor Text</Link>
这样,src/pages/articles.js就成为了前缀为 slug 的模板页面/articles。
| 归档时间: |
|
| 查看次数: |
2024 次 |
| 最近记录: |