经过一些调查,我发现使用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
页面并使用Link
Gatsby 提供的页面,您可以state
像这样通过props传递 props :
<Link to="/articles/the-slug" state={{ slug: "the-slug", ...etc }}>Anchor Text</Link>
这样,src/pages/articles.js
就成为了前缀为 slug 的模板页面/articles
。
归档时间: |
|
查看次数: |
2024 次 |
最近记录: |