user788448
user788448

Reputation: 797

Display Detail Component Using React Router

I want to display a CourseDetail component when user clicks a link using react router. But when I add router to index.js, the main page displays blank. How do I add router correctly? Thanks. Below index.js works when no router for CourseDetail.js component

ReactDOM.render(
 <BrowserRouter>
    <App />
 </BrowserRouter>,
 document.getElementById("root")
 );

Below code displays blank after adding router for CourseDetail.js `

 ReactDOM.render(
    <BrowserRouter>
      <Route path='/course/:CLASSNBR' component={CourseDetail} />      
      <Route  path="/" exact component={App} />
    </BrowserRouter>,
    document.getElementById("root")
    );

Upvotes: 0

Views: 46

Answers (1)

Cesare Polonara
Cesare Polonara

Reputation: 3860

If you are using react-router v5 you need to wrap your routes within <Switch></Switch>. If you are using react-router v6, you need to wrap your routes within <Routes></Routes>.

Upvotes: 1

Related Questions