DEV Community

CalebMcCoy04
CalebMcCoy04

Posted on

4 2

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:

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay