Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,155,825 members, 7,828,018 topics. Date: Tuesday, 14 May 2024 at 09:28 PM

React Is After My Life....please Help!!! - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / React Is After My Life....please Help!!! (1266 Views)

If Svelte Is That Great How Come React Is Dominating / React Is Going Nowhere. / Why React Is Developers' Personal Favorite? (2) (3) (4)

(1) (Reply) (Go Down)

React Is After My Life....please Help!!! by Nobody: 2:43am On Nov 19, 2021
I've been trying to create links for different pages Using react-router-dom, I imported BrowserRouter, Route and Switch but I kept getting an error that "Switch is not exported from 'react-router-dom'. Same switch that I used a couple of days back on a project and it worked o, I read react documentation and checked online including quora and reddit and observed that a lot of people were having same issue.

Since my react-router is version 6.0 I changed Switch to Routes and components to elements then removed exact, this time it threw an Invalid Hook call error, I followed the instructions on react docs and found out that I have more than one copy of react in the same app.

I don't know how to proceed from here and I have a deadline to meet. I've been stuck at this for over a day now with no solution in sight, I couldn't even sleep all night. I even created a new react app, yet the same issue.
I don't know if the problem is from my code.

Trasezengatu( this name na tongue twister)
qtguru
karleb

Please make una come help me.
Re: React Is After My Life....please Help!!! by Karleb(m): 2:48am On Nov 19, 2021
Tesan is coming. I don't know react o.

How can you have different versions of react on same app? I'm curios.

You said others have same issues online, what was their solutions?
Re: React Is After My Life....please Help!!! by qtguru(m): 6:08am On Nov 19, 2021
Onahi95:
I've been trying to create links for different pages Using react-router-dom, I imported BrowserRouter, Route and Switch but I kept getting an error that "Switch is not exported from 'react-router-dom'. Same switch that I used a couple of days back on a project and it worked o, I read react documentation and checked online including quora and reddit and observed that a lot of people were having same issue.

Since my react-router is version 6.0 I changed Switch to Routes and components to elements then removed exact, this time it threw an Invalid Hook call error, I followed the instructions on react docs and found out that I have more than one copy of react in the same app.

I don't know how to proceed from here and I have a deadline to meet. I've been stuck at this for over a day now with no solution in sight, I couldn't even sleep all night. I even created a new react app, yet the same issue.
I don't know if the problem is from my code.

Trasezengatu( this name na tongue twister)
qtguru
karleb

Please make una come help me.

Did you confirm that the library was installed in node_modules
Re: React Is After My Life....please Help!!! by valzey(m): 6:12am On Nov 19, 2021
Check your package.json and remove the extra react dependency, delete node_modules and package-lock.json or yarn.lock and refetch dependencies.

You can either use the most recent react-router and follow their latest docs https://reactrouter.com/docs/en/v6/getting-started/installation or specifically use the version of react-router you're familiar with, that's why we have package managers, you are not forced to use the latest package.

Note: react-router V6 is not backward compatible with previous versions.
Re: React Is After My Life....please Help!!! by spartan117(m): 6:52am On Nov 19, 2021
There's a new version of React router Dom that has some notable changes which are not compatible with old code. You may want to check it out.
Re: React Is After My Life....please Help!!! by Nobody: 7:03am On Nov 19, 2021
qtguru:

Did you confirm that the library was installed in node_modules
Yes it is
Re: React Is After My Life....please Help!!! by Nobody: 7:04am On Nov 19, 2021
spartan117:
There's a new version of React router Dom that has some notable changes which are not compatible with old code. You may want to check it out.
I'm using the latest model version 6.0 reason the Switch didn't work since it was no longer supported by the new version.
Re: React Is After My Life....please Help!!! by Nobody: 7:07am On Nov 19, 2021
valzey:
Check your package.json and remove the extra react dependency, delete node_modules and package-lock.json or yarn.lock and refetch dependencies.

You can either use the most recent react-router and follow their latest docs https://reactrouter.com/docs/en/v6/getting-started/installation or specifically use the version of react-router you're familiar with, that's why we have package managers, you are not forced to use the latest package.

Note: react-router V6 is not backward compatible with previous versions.
Thanks I will try it out, though I'm seeing just one react dependency in my package. jason file.
Re: React Is After My Life....please Help!!! by Nobody: 7:08am On Nov 19, 2021
Karleb:
Tesan is coming. I don't know react o.
How can you have different versions of react on same app? I'm curios.
You said others have same issues online, what was their solutions?
It worked once Switch is changed to Routes
Re: React Is After My Life....please Help!!! by spartan117(m): 7:26am On Nov 19, 2021
Onahi95:

I'm using the latest model version 6.0 reason the Switch didn't work since it was no longer supported by the new version.
Yes you need to update your codebase to reflect the changes made in the new version. Read through the docs

Onahi95:

It worked once Switch is changed to Routes
Nice
Re: React Is After My Life....please Help!!! by Nobody: 7:42am On Nov 19, 2021
spartan117:

Yes you need to update your codebase to reflect the changes made in the new version. Read through the docs


Nice
It hasn't worked yet o, I was only telling him what happens when the Switch is changed to Routes, mine didn't work
Re: React Is After My Life....please Help!!! by QuantumR: 7:52am On Nov 19, 2021
Onahi95:

It hasn't worked yet o, I was only telling him what happens when the Switch is changed to Routes, mine didn't work
import {Routes, Route} from "react-router-dom"
use this way
<Routes>
<Route path="/" element={<Home />} />
</Routes>
Re: React Is After My Life....please Help!!! by Nobody: 8:04am On Nov 19, 2021
QuantumR:
import {Routes, Route} from "react-router-dom"
use this way
<Routes>
<Route path="/" element={<Home />} />
</Routes>
I've done that already yet it throws the invalid hooks call
Re: React Is After My Life....please Help!!! by QuantumR: 8:14am On Nov 19, 2021
Onahi95:

I've done that already yet it throws the invalid hooks call

share screenshot of the actual error screen, the issue is probably not related to react router dom
Re: React Is After My Life....please Help!!! by Frontend: 10:39am On Nov 19, 2021
switch is no longer supported in react router

React latest version no more support switch.

src-
app.js

import React from react;
import Navbar from './component/Navbar;
import footer from './component/footer;
import Home from './pages/Home;
import About from './pages/About;
import {Route,Routes} from 'react-router-dom';
Const App=()=>{
return (
<div>
<Navbar/>
<Routes>
<route path='/' element={<Home/>}/>
<route path='/About' element={<About>/}/>
<route path='/Contact' element={<Contact/>}/>
</Routes>
<footer/>
</div>
);
}
export default App;
Re: React Is After My Life....please Help!!! by olukunle50: 11:21am On Nov 19, 2021
Use Routes, instead of Switch, Switch is no longer supported
Re: React Is After My Life....please Help!!! by Supreme145(m): 1:40pm On Nov 19, 2021
Frontend:
switch is no longer supported in react router

React latest version no more support switch.

src-
app.js

import React from react;
import Navbar from './component/Navbar;
import footer from './component/footer;
import Home from './pages/Home;
import About from './pages/About;
import {Route,Routes} from 'react-router-dom';
Const App=()=>{
return (
<div>
<Navbar/>
<Routes>
<route path='/' element={<Home/>}/>
<route path='/About' element={<About>/}/>
<route path='/Contact' element={<Contact/>}/>
</Routes>
<footer/>
</div>
);
}
export default App;
Already tried according to the write up
Re: React Is After My Life....please Help!!! by Supreme145(m): 1:40pm On Nov 19, 2021
olukunle50:
Use Routes, instead of Switch, Switch is no longer supported
.
Re: React Is After My Life....please Help!!! by Csami(m): 10:46pm On Nov 19, 2021
React navigation suck. Angular router the best
Re: React Is After My Life....please Help!!! by jikins(m): 4:14am On Nov 20, 2021
Csami:
React navigation suck. Angular router the best

Pele oh
Re: React Is After My Life....please Help!!! by jikins(m): 4:16am On Nov 20, 2021
olukunle50:
Use Routes, instead of Switch, Switch is no longer supported

I only just found this out recently, Even useHistory self is no longer supported
Re: React Is After My Life....please Help!!! by niel63(m): 7:18am On Nov 23, 2021
Bro share your code via github make we help out.
Re: React Is After My Life....please Help!!! by Roadyroadie: 1:40am On Nov 26, 2021
Use Nextjs if you can.

(1) (Reply)

Unix Shell Scripting Newbies / Young Nigerians Unveil Swapnaija App / I Am Looking For A Java Developer

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 30
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.