Home > Software engineering >  Route component in BrowserRoute doesn't work. When Route is removed it works
Route component in BrowserRoute doesn't work. When Route is removed it works

Time:12-22

I am following a tutorial. The guy uses a code like this. I can't figure it out why it doesn't work on my machine. I installed all the required packages. I am wondering whether the syntax hasn't changed (the tutorial is 2 years old).

import { BrowserRouter, Route } from 'react-router-dom';
import Welcome from './components/Welcome';

function App() {
  return (
    <BrowserRouter>
      <Route path="/" component={Welcome} exact={true} />
    </BrowserRouter>
  );
}

export default App;

When I tried it without the component but with , it worked.

CodePudding user response:

on React router v6 it should be

    <BrowserRouter>
      <Routes>
        <Route path="/" component={<Welcome/>} exact={true} />
      </Routes>
    </BrowserRouter>
  • Related