相关文章推荐
腼腆的西瓜  ·  React-admin - ...·  2 月前    · 
大力的荒野  ·  Getting started with ...·  2 月前    · 
追风的花生  ·  Map in React js with ...·  2 月前    · 
温柔的保温杯  ·  How to Use the ...·  2 月前    · 
奔跑的凳子  ·  Loading in Rive Files ...·  2 月前    · 
风流倜傥的杨桃  ·  ​2022 ...·  1 年前    · 
满身肌肉的大脸猫  ·  推荐 5 ...·  1 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

Why do I get this error when I declare a "component" property in "Route";

Property 'component' does not exist on type 'IntrinsicAttributes & (PathRouteProps | LayoutRouteProps | IndexRouteProps)'.

import { Routes, Route } from 'react-router-dom'
import './App.css'
import HomePage from './pages/HomePage'
function App() {
  return(
    <Routes>
      <Route path="/" component={HomePage}/>
    </Routes>
} ``` The problem might be; because I dont use 'exact path="/"' that might also give an error
                react-router just got an update that breaks all old code again. Perhaps you accidentally got the latest react-router with an old tutorial?
– Evert
                Nov 7, 2021 at 23:30

With the upgrade of react-router-dom to version 6.0, certain properties have changed. The syntax you are using will work fine for version 5.0. To update to v6, make this change to your code:

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

Version 6 of the router changed the way to create these kinds of routes - https://reactrouterdotcom.fly.dev/docs/en/v6/getting-started/overview

nanoTitan got the right answer with:

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

Regarding exact - I do not think you need to worry about this any more. If you have a route like / and another route like /about version 6 is smart enough to route to about. Apparently, even if you have routes like /user/:uuid and /user/new - navigating to /user/new will be understood as the new page.

I also found that tutorials and the like are all about version 5, it is a confusing environment to learn in.

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.