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

137
Views
unable to render my components when using with ROUTE in REACTJS

image showing react appcode for app.js .. i have been trying to use ROUTE but unable to render my components

import './App.css';
import Home from './pages/Home';
import Rooms from './pages/Rooms';
import SingleRoom from './pages/SingleRoom';
import Error from './pages/Error';
import { Route, Switch} from 'react-router-dom';


function App() {
  return (
    <>
      <Route exact path="/" component={Home}/>
      <Route exact  path="/rooms/" component={Rooms}/>
      <Route exactpath="/singleroom" component={SingleRoom}/>

    </>
  );
}

export default App;
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You need to wrap your Routes in the Router and Routes components.

This is for react-router-dom v6:

import './App.css';
import Home from './pages/Home';
import Rooms from './pages/Rooms';
import SingleRoom from './pages/SingleRoom';
import Error from './pages/Error';
import { Routes, Route, Switch, BrowserRouter as Router } from 'react-router-dom';

function App() {
  return (
    <Router>
      <Routes>
        <Route path="/" element={<Home />} />
        <Route path="/rooms/" element={<Rooms />} />
        <Route path="/singleroom" element={<SingleRoom />}/>
      </Routes>
    </Router>
  );
}

export default App;
about 4 years ago · Juan Pablo Isaza Report

0

Assuming you already wrapped your app with <Router> inside your index.js file, now every time you use routes You need to wrap them with <Switch>

<Switch>
    <Route exact path="/" component={Home}/>
    <Route exact  path="/rooms/" component={Rooms}/>
    <Route exactpath="/singleroom" component={SingleRoom}/>
</Switch>
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!