DEV Community

CalebMcCoy04
CalebMcCoy04

Posted on

Switch vs Routes in React V5 vs. V6

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>
Enter fullscreen mode Exit fullscreen mode

now we will show version 5

import {Switch, Route} from 'react-router-dom'

function App(){
  return (
    <Switch>
      <Route exact path="/">
        <Component/>
      </Route
    <Switch>
Enter fullscreen mode Exit fullscreen mode

side note exact sometimes cause an error so try deleting it if this happens.

sources:

Top comments (0)