router
router copied to clipboard
useMatch Invariant failed with react 17
Describe the bug
I'm using React 17. I have const match = useMatch(addRoute.id) in my component. When I navigate to a different route. I get Invariant failed.
Also this error

My route is like this
export const addRoute = rootRoute.createRoute({
path: "add",
component: Add,
validateSearch: z
.object({
ids: z.array(z.string()).optional(),
})
.optional(),
});
The navigation and all the functionality works however.
Your Example Website or App
https://stackblitz.com/edit/tanstack-router-nyjcvm?file=src/main.tsx
Steps to Reproduce the Bug or Issue
In the basic example, change the React version to 17. (done in the linked stackblitz) Navigate from posts to home tab
Expected behavior
no errors
Screenshots or Videos
No response
Platform
- OS: Linux
- Browser: Chromium
- Version: 0.0.1-beta.36
Additional context
No response
You can use useMatch(addRoute.id, {strict: false }) if you do not always expect your route to match, it will return optional result.
I do expect it to always match. Anyways if I add strict: false, I still get a lot of errors in the console.
Fixed now.