Introduction
Created by Codedamn about a year ago
No description provided
10 Comments
Fails to compile Hi, My code is the same but my app doesnt run and says :
src\App.js
Line 8:53: 'home' is not defined no-undef
Line 9:58: 'about' is not defined no-undef
which makes sense since we didnt use it but it does run for you… my full code is
import React from 'react'
import { BrowserRouter as Router, Switch, Route, Link } from 'react-router-dom'
function App() {
return (
<Router>
<Switch>
<Route path='/' exact={true} component={home} />
<Route path='/about' exact={true} component={about} />
</Switch>
</Router>
)
}
export default App
\
Hacking <Switch> When you mentioned that it returns the first fulfilled requirement, I thought, well, why not just put “/” last then?
This also works:
<Switch>
<Route path="/About" component={About} />
<Route path="/" component={Home} />
</Switch>
BrowserRouter is not working don't know why
This section should be updated becuase react router currently doesn't support browser router and other things in V6
For anyone seeing issues trying the hello-world example... you can no longer put in the content in between the opening and closing <react> tags. The content you want is now passed in as jsx through the "element" prop.
So it's now <Route path="whatever" element={your JSX}/>
And you can no longer do: <Route path="whatever">Your JSX</Route>
If you are coding currently, the explained code in this video won't work You can check this for references
import React, { useState } from 'react' import { BrowserRouter, Route, Link, Routes } from 'react-router-dom'
//In this .jsx we have routing
function App() { return <BrowserRouter> <div> <nav> <ul> <li> <Link to="/about">About</Link> </li> <li><Link to="/">Home</Link></li> </ul> </nav> <Routes> <Route path="/about" element={<h1>Router Home</h1>} /> </Routes> </div> </BrowserRouter> }
export default App
Please update this course Codedamn.
Ritwik Raj Singha few seconds ago In the updated version of React, the syntax has changed. If you're experiencing any difficulties with this tutorial, you can use the following syntax:
import React from 'react'; import '../App.css'; import { BrowserRouter, Route, Routes } from 'react-router-dom';
export default function ReactRouter() { return (
<div> <BrowserRouter> <Routes> <Route path="/hello-world" element={<h1>I am on the Hello World route</h1>} /> </Routes> </BrowserRouter> <h2>I am just an h2</h2> </div> ); }plz update the course it is so costly and still things are not updated
//Updated Syntax For Route Usage.
import React from 'react'; import { BrowserRouter, Route, Routes,Link } from 'react-router-dom';
export default function ReactRouter() { return (
<div> <BrowserRouter> <h3>Navbar</h3> <nav> <ul> <li><Link to="/hell-world">Go to Hell</Link></li> <li><Link to="/">Go Home</Link></li> <li><Link to="/hello-world">Go to Hello World</Link></li> </ul> </nav> <h3>Portal Below</h3> <hr /> <Routes> <Route path="/hello-world" element={<h1 style={{background: 'lightgreen'}}>I am on the Hello World route</h1>} /> <Route path="/" element={<h1 style={{background: 'lightblue'}}>I am on the Home route</h1>} /> <Route path="/hell-world" element={<h1 style={{background: 'red'}}>I am on the Hell World route</h1>} /> </Routes></BrowserRouter>
<hr />
<h2>I am just an h2</h2>
</div>
);
}