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
–
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.