【问题标题】:Property 'type' is missing in type '{}' but required in type 'Props'类型“{}”中缺少属性“类型”,但类型“道具”中是必需的
【发布时间】:2021-11-05 16:41:04
【问题描述】:

** 在 react-router v6 中,我正在传递元素,所以在打字稿中它要求道具我如何解决这个问题**

     <Route path="dashboard" element={<Dashboard />} />
     <Route path="fellows" element={<AllFellow />} />
     <Route path="schools" element={<AllSchool />} />
     <Route path="pgestudents" element={<PgeStudents />} />
     <Route path="ecestudents" element={<EceStudents />} />
     <Route path="fellow/:fellowid" element={<IndividualFellow />} />
</Routes>```

**Type '{}' is missing the following properties from type 'Props':**



【问题讨论】:

  • 请提供足够的代码,以便其他人更好地理解或重现问题。

标签: reactjs react-router react-router-dom


【解决方案1】:

如果你在组件文件中正确定义了props,你应该通过传递参数名称来调整元素声明,例如:

<Dashboard dashboard_id={''} />

而不仅仅是

 <Dashboard/>

Visual Studio 代码提供此选项作为对错误的快速修复

【讨论】:

    猜你喜欢
    • 2021-07-26
    • 2019-09-19
    • 1970-01-01
    • 2020-12-25
    • 2020-08-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-30
    相关资源
    最近更新 更多