Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Error "Uncaught Error: [App] is not a <Route> component. All component children of <Routes> must be a <Route> or <React.Fragment>"

I am trying to use routing for the first time and followed the exact instructions from Youtube

App.jsx

import React, { Component } from "react";
import { Route, Routes } from "react-router-dom";
import "./App.css";
import Customer from "./components/customer";
import Movies from "./components/moviesComponent";
import NotFound from "./components/not-found";
import Rentals from "./components/rentals";

class App extends Component {
  render() {
    return (
      <Routes>
        <Route path="/movies" element={<Movies />}></Route>
        <Route path="/rentals" element={<Rentals />}></Route>
        <Route path="/customers" element={<Customer />}></Route>
        <Route path="/not-found" element={<NotFound />}></Route>
      </Routes>
    );
  }
}

export default App;

index.js

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

import React from "react";
import ReactDOM from "react-dom/client";
import "./index.css";
import App from "./App";
import reportWebVitals from "./reportWebVitals";
import "bootstrap/dist/css/bootstrap.css";
import "font-awesome/css/font-awesome.css";
import "hover.css";
import "./App.css";
import { BrowserRouter, Routes } from "react-router-dom";

const root = ReactDOM.createRoot(document.getElementById("root"));
root.render(
  <BrowserRouter>
    <Routes>
      <App />
    </Routes>
  </BrowserRouter>
);

// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
reportWebVitals();

I get the following error:

Uncaught Error: [App] is not a <Route> component. All component
children of <Routes> must be a <Route> or <React.Fragment>

I am using react-router latest version.

>Solution :

Just render App in the router, not a Routes component. Only Route and React.Fragment components are valid children of the Routes component.

const root = ReactDOM.createRoot(document.getElementById("root"));
root.render(
  <BrowserRouter>
    <App />
  </BrowserRouter>
);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading