What’s the better way to configure routes in App.js in React with react-router-dom

  javascript, react-router-dom, reactjs

In App.js of React, we can either:

<div className="App">
  <Router>
    <Switch>
      <Route
        path="/basics"
        >
        <BasicsPage></BasicsPage>
      </Route>
      // other routes
    </Switch>
  </Router>
</div>

OR

<div className="App">
  <Router>
    <Switch>
      <Route
        path="/basics"
        component={BasicsPage}
        >
      </Route>
      // other routes
    </Switch>
  </Router>
</div>

Just wondering which is the better way to write it and if there’ any difference between the two? Thanks!

Source: Ask Javascript Questions

LEAVE A COMMENT