Hello today I am going to be talking about using Switch vs. Routes hook in react and the basic setup. to get started first run this command in your terminal to install the react router.
npm install react-router-dom
add @5 at the end to install version 5
Switch and Routes is just a special version of the tag
Next lets go over what the syntax will look like this will be version dependent!
first we will show the version 6
import {Routes, Route} from 'react-router-dom'
function App(){
return (
<Routes>
<Route path="/" element={Component/>}/>
<Routes>
now we will show version 5
import {Switch, Route} from 'react-router-dom'
function App(){
return (
<Switch>
<Route exact path="/">
<Component/>
</Route
<Switch>
side note exact sometimes cause an error so try deleting it if this happens.
Top comments (0)