I am having trouble using the EXACT property for my routes, I am using React 18
import { BrowserRouter, Route } from 'react-router-dom';
import Landing from './pages/Landing'
import FanbaseMap from './pages/FanbaseMap'
function Routes() {
return (
<BrowserRouter>
<Route exact path="/">
<Landing />
</Route>
<Route exact path="/map">
<FanbaseMap />
</Route>
</BrowserRouter>
);
}
Type ‘{ children: Element; exact: true; path: string; }’ is not
assignable to type ‘IntrinsicAttributes & RouteProps’. Property
‘exact’ does not exist on type ‘IntrinsicAttributes & PathRouteProps’.
I need to create routes that direct to an exact page using React and react-router-dom.
2
Answers
Check version on react-router. React router v6 doesn’t support exact anymore.
Here is detailed answer:
Property 'exact' does not exist on type
react-router-dom@6
Route
components have noexact
prop. In fact, in RRDv6 routes and now always exactly matched using a route ranking score.Route
components into theRoutes
component.Routes
is the spiritual successor to the RRDv4/5Switch
component and handles the route matching logic.Route
component’selement
prop. All route content is on theelement
prop. Only otherRoute
components are valid children in the case of nested routes.exact
prop since it does nothing.Example: