首页 > 解决方案 > 类型上不存在属性“组件”

问题描述

为什么在“路由”中声明“组件”属性时出现此错误;类型“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

解决方案


随着 react-router-dom 升级到 6.0 版本,某些属性发生了变化。您使用的语法适用于 5.0 版。要更新到 v6,请对您的代码进行以下更改:

<Route path="/" element={<HomePage />} />

推荐阅读