0

I am new to React.js and I was trying to build a blog; however, after I add some components and try to see it on the browser, I met this error: a <route> is only ever to be used as the child of <routes> element, never rendered directly. please wrap your <route> in a <routes>. I read a lot of posts but still not fix it.

index.js:

import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import { BrowserRouter as Router, Route, BrowserRouter } from 'react-router-dom';

const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
  <React.StrictMode>
    <Router>
      <Route path = "/" component={App}/>
    </Router>
  </React.StrictMode>,
  document.getElementById('root')
);

Appreciate for any help.

I wish someone can tell me why and how to fix it. Thanks.

yic_l
  • 19
  • 3
  • Does this answer your question? https://stackoverflow.com/questions/69832748/error-error-a-route-is-only-ever-to-be-used-as-the-child-of-routes-element – Lin Du Jun 05 '23 at 04:09
  • 1
    I mean, the error message tells you EXACTLY what the issue is and EXACTLY how to fix it. Wrap your `` in a ``. Just look at the documentation for the `react-router-dom` library, it will give examples – Jayce444 Jun 05 '23 at 04:21

1 Answers1

0

you can used Routes in App.js like that

<Routes>
  <Route path = "/" component={Home}/>
</Routes>