【问题标题】:TypeError: Cannot read properties of undefined ( 'current')TypeError:无法读取未定义的属性(\'current\')
【发布时间】:2022-08-17 05:37:18
【问题描述】:

错误 - components\\Product.jsx (9:35) @ Product TypeError: Cannot read properties of undefined (reading \'current\') 7 |返回 ( 8 |

9 | <链接 href={/product/${slug.current}}> | ^ 10 | 11 | 12 | <img

标签: reactjs next.js sanity


【解决方案1】:

发生这种情况是因为有一个或多个未定义的 slug,因此它无法呈现 current 属性。尝试使用optional chaining operator(即slug?.current)或有条件地检查是否存在slug。

【讨论】:

  • 您可能还想使用validation(即Rule.required())确保在您的Sanity Studio 中需要您的slug。
【解决方案2】:

如果您使用理智,请检查您是否有任何未命名的产品。如果是,请将其删除或添加信息,然后发布。这应该可以解决您的问题。

让我知道这是否有帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-11-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-24
    • 2019-08-19
    • 1970-01-01
    相关资源
    最近更新 更多