New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ViteJS - Uncaught Error: useRoutes() may be used only in the context of a <Router> component #7937
Comments
Thanks for your report. We'lll take a look at this. |
I went through the first steps of the tutorial without any trouble. |
Thanks @septentrion-730n . Will investigate a bit more on my end. Appreciate the quick turnaround! |
I'll set this as "closed" - will reopen it if required! |
I'm starting to have this bug with |
@MBach Please provide a reproduction if you think this is a react-admin bug. |
Well, currently I'm short in time, like most of us, but I'll try to create a repro. |
I'm also having a very similar bug to this with react-router-dom 6.4.1 - if you need to reproduce, just upgrade any of your own React Admin projects (that use useRoutes or useLocation) to the same version of React Router DOM, and it should occur. I'm also getting this error after upgrading React Router DOM: |
Confirmed: react-router 6.4.1 breaks react-admin. Reopening and marking this as a bug. |
Nope, I was wrong: react-admin works well with react-router 6.4.1. This error occurs if there are several instances of React-router uses a singleton - this is a limitation of the library. So you have to fix that on your side, there is nothing that react-admin can do. |
I hear you. I tried reproducing this error with a fresh clone of one of the repositories above. I couldn't get the bug to manifest in the repro, and that does make it seem like the issue isn't with React Admin. But, I've been maintaining our React Admin project for about 2 years now, and we've never had this problem before. It's a fairly sophisticated project with a decently-large scope. (I've been in talks with our company for a couple of months to get us an enterprise license as well, by the way... it's just that we're a huge company and things move really slow.) The thing is, we didn't have any problems like this for the last couple of years we've been using React Admin. We didn't have these problems when we finished the upgrade from version 3 to version 4 of React Admin (and upgraded React Router to version 6, as well). The only time we have these unique errors is when we upgrade from version 6.3.0 of React Router to version 6.4.x, and the errors are coming from somewhere inside React Admin. It's something to do with the context from React Router not making it through into the Admin component. When we downgraded back to 6.3.0 of React Router, all of these strange bugs went away again. Moreover, when I run |
@MBach / @bhaskarmurthy - Boy, do I feel foolish. @fzaninotto was 100% correct: this bug had nothing to do with React Admin (at least, for me). Up until React Router v6.4.x it was possible to import the Route component from Can you both check to see if you've made the same mistake? If so, I hope this solves your problems as well! |
So, once more for clarity, do NOT do this if you have any custom routes in your app:
Instead, this is the correct approach which will hopefully fix your issues:
God, I really do hate React Router and its endless parade of syntax changes. |
Good asumption with custom routes, that's what I thought too. However, I do have checked my code, and I have react-router-dom only. |
@MBach Did you solve it? |
Not yet. For now I'm staying with fixed |
Another anecdote related to this root issue that might be helpful. Was just doing an upgrade pass on my application, going through my dependencies. As part of that process I upgraded to react-router-dom 6.6.1 from 6.4.2 and encountered the issue above. After hunting around for a possible cause, I came across this thread here in GitHub. I played around with some trial and error, upgrading to 6.4.5, no go. 6.5.0, no go. Hmmm. Then, I was doing some unrelated cleanup and accidentially removed the dependency entirely from my package.json. I had restarted Node in my IDE and was checking something else out and viola!! the browser page refreshed and the app did not through the error. A Christmas miracle! To summarize my situation: I previously had "react-router-dom": "^6.x.x" explicitly added to my package.json. |
I had the same issue using react-router@6.4.4. Deleted the node_modules directory and deleted pnpm-lock.yaml. |
I also encountered this error. What is interesting is that it gets reproduced when react-router-dom gets new version. To reproduce it locally I delete react-router-dom and install again. After that react-admin break consistently when you click on resource. Temporal fix is to update react-router-dom to latest version, however after third time it is rather unpleasant. |
Chiming in for anyone else googling this issue... We encountered this error while moving react-admin from one framework to a fresh Create React App. For this case, we wanted to avoid deleting "resolutions":{
"react-router-dom": "6.8.0",
"react-router": "6.8.0"
} |
Just encountered this error and I solved it by using react-admin: "4.7.4". |
I just had this issue and solved it by deleting |
I confirm duplicates as the cause of the problem.
After manual cleanup of yarn.lock to keep only references to 6.21.2, the server is fine again. |
What you were expecting:
react-admin should render as expected
What happened instead:
react-router does not render any routes, and instead throws an exception:
Steps to reproduce:
react-ts
templateRelated code:
Other information:
Environment
The text was updated successfully, but these errors were encountered: