question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ViteJS - Uncaught Error: useRoutes() may be used only in the context of a <Router> component

See original GitHub issue

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:

Uncaught Error: useRoutes() may be used only in the context of a <Router> component

Steps to reproduce:

  1. Set up a new Vite project using react-ts template
  2. Follow tutorial to set up a react-admin component
  3. Launch app

Related code:

insert short code snippets here

Other information:

Environment

  • React-admin version:
  • Last version that did not exhibit the issue (if applicable):
  • React version:
  • Browser:
  • Stack trace (in case of a JS error):
Uncaught Error: useRoutes() may be used only in the context of a <Router> component.
    invariant index.tsx:24
    useRoutes index.tsx:642
    Routes index.tsx:344
    React 12
    unstable_runWithPriority scheduler.development.js:468
    React 4
    unstable_runWithPriority scheduler.development.js:468
    React 3
    workLoop scheduler.development.js:417
    flushWork scheduler.development.js:390
    performWorkUntilDeadline scheduler.development.js:157
    js scheduler.development.js:180
    js scheduler.development.js:645
    __require chunk-CEDYW5NB.js:11
    js index.js:6
    __require chunk-CEDYW5NB.js:11
    React 2
    __require chunk-CEDYW5NB.js:11
    js React
    __require chunk-CEDYW5NB.js:11
    <anonymous> react-dom:1
index.tsx:24:19

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:17 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
MBachcommented, Oct 20, 2022

Not yet. For now I’m staying with fixed react-router-dom: 6.3.0

1reaction
bhaskarmurthycommented, Jul 7, 2022

Thanks @septentrion-730n . Will investigate a bit more on my end. Appreciate the quick turnaround!

Read more comments on GitHub >

github_iconTop Results From Across the Web

React Router V6 - Error: useRoutes() may be used only in the ...
After saving I am getting the following error: Error: useRoutes() may be used only in the context of a component. I am wondering...
Read more >
useRoutes() may be used only in the context of Router ...
The error "useRoutes() may be used only in the context of a Router component" occurs when we try to use the useRoutes hook...
Read more >
uncaught [error: useroutes() may be used only in the context of ...
The issue here is that you are specifying two different versions. The router you are using is from v5, but the Routes and...
Read more >
React Router V6 - Error: useRoutes() may be used only in the ...
Coding example for the question React Router V6 - Error: useRoutes() may be used only in the context of a component-Reactjs.
Read more >
Is using useRoutes instead of the OG way bad in any way?
22 votes, 13 comments. import React, { Fragment } from "react"; import { useRoutes } from "react-router-dom"; import LoginScreen from…
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found