14
loading...
This website collects cookies to deliver better user experience
<Switch>
component to wrap all of our Routes, now the the Switch component has been replaced by <Routes>
. It is essentially the same thing as switch, however some new features have been added to the <Route>
component it self.<Route>
component. exact
prop on the component so that it goes to the particular route. However in V6, there is no need of this prop as React Router now always looks for the exact path without being told.element
prop in the route and place the component inside it. The pros of this are that you can simply inject whichever component one needs depending on its route rather than placing it in each route component.export default function App() {
return (
<div>
<Switch>
<Route path="/page1">
<Page1/>
</Route>
<Route exact path="/page2">
<Page2/>
</Route>
</Switch>
</div>
)
}
export default function App() {
return (
<div>
<Routes>
<Route path="/page1" element={<Page1/>} />
<Route path="/page2" element={<Page2/>} />
</Routes>
</div>
)
}
Routes
instead of Switch
, removal of exact and use of the element prop.