. Advertisement .
..3..
. Advertisement .
..4..
The error “Property ‘exact’ does not exist” is confusing and annoying to deal with, but it happens and is not too hard to fix. The message is pretty self-explanatory, but this blog will look into it in more detail, how to fix it and when it may happen.
When Do You Get The Error “Property ‘exact’ does not exist”?
When you try to utilize react-router-dom, you may get the following error.
TypeScript error in
/Users/veselinkontic/Projects/givellet/frontend/src/components/index.tsx(9,37):
Type ‘{ path: string; exact: true; }’ is not assignable to type ‘IntrinsicAttributes &
(PathRouteProps | LayoutRouteProps | IndexRouteProps)’.
Property ‘exact’ does not exist on type ‘IntrinsicAttributes & (PathRouteProps |
LayoutRouteProps | IndexRouteProps)’. TS2322
How to fix the error “Property ‘exact’ does not exist”
Approach 1: React router version 6 does not support exact.
Here, if you’re utilizing React Router v6, you won’t be able to use exact.
Utilize this if you’re utilizing v5:
<Route exact path="/" component={Home} />
Utilize this if you’re utilizing v6:
<Route path="/" element={<Home />} />
Now, you have fixed your issue.
Approach 2: Follow this guide
Excepting the above solution, there is another solution for you to solve the error “Property ‘exact’ does not exist”. Let’s follow this guide:
React router only does partial matching, so it would incorrectly revert to the Users route when /users matches /users/create. A route’s exact parameter disables partial matching and ensures that it will only ever return the route if the path matches the current URL.
The precise keyword is not supported by the new React-Router. You can easily remove it from the route, and everything will still function properly. Additionally, you must use the element and provide the element tag into it rather than the component.
Conclusion
We hope our blog post on how to solve the “Property ‘exact’ does not exist” problem was useful. With this information, you should be able to handle this annoyance and a slew of other concerns when you design your application. Please leave a comment if you want to learn more about the topic or if you have any questions or ideas to share. Thank you for taking the time to read this!
Read more
→ Property Does Not Exist On Type Object In TypeScript: Cause And Solutions
Leave a comment