【问题标题】:Gatsby: Changing Default Path Names盖茨比:更改默认路径名称
【发布时间】:2020-04-29 02:48:11
【问题描述】:

我刚刚开始使用 Gatsby 并使用以下模板:yellowcake

我想更改默认路径名(特别是帖子),但在尝试更改 config.yml 中的“帖子”后,我尝试使用新路径访问的任何页面都会崩溃。我基本上想更改以下内容:

domain.com/posts/some-article-in-the-content-posts-folder

domain.com/my-custom-path/some-article-in-the-content-posts-folder

【问题讨论】:

标签: reactjs path gatsby


【解决方案1】:

除了替换config.yml中的路径外,您还需要将src/cms/cms.js中的设置更改为以下

CMS.registerPreviewTemplate('my-custom-path', ({ entry }) => (
  <SinglePostTemplate {...entry.toJS().data} />
))

P.S.完成更改后,清理 gatsby 缓存并重建应用程序。

【讨论】:

  • 谢谢,我将尝试使用 config.yml 和 cms.js。目前,cms.js 看起来像这样:https://github.com/thriveweb/yellowcake/blob/master/static/admin/config.yml
  • 让我知道上述解决方案是否适合您
  • 我收到一条错误消息:Cannot read property 'component---src-templates-single-post-js' of undefined which it says is来自 .cache/loader.js 我看到了这个错误当我尝试访问任何自定义路径页面时。
  • 你能不能试着清理一下 gatsby 缓存并重建它
  • 为了帮助将来尝试自定义此模板中路径的任何人,我进行了以下编辑以将“帖子”更改为自定义路径名称:将“帖子”的所有实例编辑到我的config.yml 中的所需路径名,将 cms.js 中的“posts”编辑为我所需的路径名,并在 SinglePost.js 的 pageQuery 部分将“posts”编辑为我所需的路径名。更改这些后,我在终端中键入“gatsby clean”以清除缓存,然后键入“npm run build”和“npm run start”以查看没有问题的更改。
猜你喜欢
  • 2017-04-13
  • 1970-01-01
  • 2020-07-02
  • 2013-09-03
  • 1970-01-01
  • 1970-01-01
  • 2021-09-27
  • 1970-01-01
  • 2013-11-04
相关资源
最近更新 更多