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

140
Views
What is wrong with the structure of my 'BrowserRouter', 'Routes' and 'Route' in my function App()?

I am attempting to follow a tutorial while learning React.JS and I am running into an issue because the tutorial is using an older version of React and I am stuck trying to figure out how to use BrowserRouter, Routes, and Route.

Can anyone assist me in trying to re-structure the code so it works with the updated version of React? I have tried reading through documentation and tried to mix around a few solutions with no success. Any help is much appreciated!

import React from 'react';
import { BrowserRouter, Routes, Route } from 'react-router-dom';
import "bootstrap/dist/css/bootstrap.min.css";

import Navbar from "./components/navbar.component.js";
import PortfolioList from "./components/portfolio-list.component";
import EditPortfolio from "./components/edit-portfolio.component";
import CreatePortfolio from "./components/create-portfolio.component";
import CreateUser from "./components/create-user.component";

function App() {
  return (
    <Routes>
      <Navbar />
      <br/>
      <Route path="/" exact component={PortfolioList} />
      <Route path="/edit/:id" exact component={EditPortfolio} />
      <Route path="/create" exact component={CreatePortfolio} />
      <Route path="/user" exact component={CreateUser} />
    </Routes>
  );
}

export default App;

The following is the 'error' I'm generating on runtime:

Error: [Navbar] is not a 'Route' component. All component children of 'Routes' must be a 'Route' or 'React.Fragment'

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

0

Only Route components and React.Fragments can be a child of the Routes component, and vice-versa. Move the non-Route components out of Routes. The Route component API also changed in version 6, there is no longer render and component props, the routed components are passed to the element prop as JSX, and routes are now always exactly matched, so there's no longer the exact prop as well.

function App() {
  return (
    <>
      <Navbar />
      <br/>
      <Routes>
        <Route path="/" element={<PortfolioList />} />
        <Route path="/edit/:id" element={<EditPortfolio />} />
        <Route path="/create" element={<CreatePortfolio />} />
        <Route path="/user" element={<CreateUser />} />
      </Routes>
    </>
  );
}
about 4 years ago · Juan Pablo Isaza Report

0

you can use the "BrowserRouter" tag followed by the "Switch" tag then you can now use the "Route" tag to specify the path of each component

about 4 years ago · Juan Pablo Isaza Report

0

you can use the "BrowserRouter" tag followed by the "Switch" tag then you can now use the "Route" tag to specify the path of each component.

    return (
        <>
            <BrowserRouter>
                <Switch>
                    <Route path="/" exact component={DashBoard} />
                    <Route path="/specialistes" exact component={Specialistes} />
                    <Route path="/findgarages" exact component={FindGarage} />
                    <Route path="/garages" exact component={Garages} />
                </Switch>
            </BrowserRouter>
        </>
    )````
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!