react-router - 类型上不存在属性“组件”
问题描述
为什么在“路由”中声明“组件”属性时出现此错误;类型“IntrinsicAttributes & (PathRouteProps | LayoutRouteProps | IndexRouteProps)”上不存在属性“组件”。
import { Routes, Route } from 'react-router-dom'
import './App.css'
import HomePage from './pages/HomePage'
function App() {
return(
<div>
<Routes>
<Route path="/" component={HomePage}/>
</Routes>
</div>
)
} ``` The problem might be; because I dont use 'exact path="/"' that might also give an error
解决方案
随着 react-router-dom 升级到 6.0 版本,某些属性发生了变化。您使用的语法适用于 5.0 版。要更新到 v6,请对您的代码进行以下更改:
<Route path="/" element={<HomePage />} />
推荐阅读
- c++ - 具有未知结构的类作为成员
- html - 我想要地址表下方的订单信息表
- css - 当先例输入为空且未聚焦时隐藏元素
- prometheus - Prometheus config doesn't work with Spring boot 2.3.0: ClassNotFoundException: io.micrometer.prometheus.HistogramFlavor
- authentication - 从 Github Laravel Socialite 注销
- python - 为什么 matplotlib.figure.Figure 对象存储来自以下 pandas.DataFrame.plot 命令的数据?
- oracle - 应打印带有复选框的选定项目
- c++ - 如何使用函数(而不是构造函数)将派生类对象分配给基类指针
- testing - TestCafe 无头定位参数
- yacc - 正确输入后无法继续解析