Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

254
Views
I'm facing this error in client side in React,js

index.js

import React from 'react';
import ReactDOM from 'react-dom';

import App from './App';

ReactDOM.render(<App />, document.querySelector('#root'));

App.js

import React from 'react';

import { BrowserRouter, Routes, Route } from 'react-router-dom';

import Join from './components/Join';
import Chat from './components/Chat';

const App = () => (
    <Routes>
        <Route path='/' exact component={Join} />
        <Route path='/chat' component={Chat} />
    </Routes>
);

export default App;

It thows error like "Error: useRoutes() may be used only in the context of a component."

Here is the ERROR: "

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You have to wrap your app in the BrowserRouter component in order to be able to use routing

So the code in index.js will be as follows

import React from 'react';
import ReactDOM from 'react-dom';
import { BrowserRouter } from 'react-router-dom';


import App from './App';

ReactDOM.render(<BrowserRouter> <App /> </BrowserRouter>, document.querySelector('#root'));

You could instead wrap the app in App.js

import React from 'react';

import { BrowserRouter, Routes, Route } from 'react-router-dom';

import Join from './components/Join';
import Chat from './components/Chat';

const App = () => (
  <BrowserRouter>
    <Routes>
        <Route path='/' exact component={Join} />
        <Route path='/chat' component={Chat} />
    </Routes>
   </BrowserRouter>
  );
    export default App;

but for cleaner code, do the first approach

about 4 years ago · Juan Pablo Isaza Report

0

Wrap your code inside <BrowserRouter> making sure it isn’t in the app itself but higher up in the tree.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!