how to use react router
import React from "react";
import {
BrowserRouter as Router,
Switch,
Route,
Link
} from "react-router-dom";
export default function App() {
return (
<Router>
<div>
<nav>
<ul>
<li>
<Link to="/">Home</Link>
</li>
<li>
<Link to="/about">About</Link>
</li>
<li>
<Link to="/users">Users</Link>
</li>
</ul>
</nav>
{/* A <Switch> looks through its children <Route>s and
renders the first one that matches the current URL. */}
<Switch>
<Route path="/about">
<About />
</Route>
<Route path="/users">
<Users />
</Route>
<Route path="/">
<Home />
</Route>
</Switch>
</div>
</Router>
);
}
function Home() {
return <h2>Home</h2>;
}
function About() {
return <h2>About</h2>;
}
function Users() {
return <h2>Users</h2>;
}
$ npm install --save react-router
npx create-react-app demo-app
cd demo-app
import React from "react";
import {
BrowserRouter as Router,
Switch,
Route,
Link
} from "react-router-dom";
export default function App() {
return (
<Router>
<div>
<nav>
<ul>
<li>
<Link to="/">Home</Link>
</li>
<li>
<Link to="/about">About</Link>
</li>
<li>
<Link to="/users">Users</Link>
</li>
</ul>
</nav>npm install --save react-router-domnpm install react-router-dom
Also in JavaScript:
- jsx-a11y/alt-text
- nodemon.json env
- check if string only contains integer digits numbers javascript
- app.route()
- next js create store
- electron iframe require is not defined
- js loop ul
- node js get file name without extension
- js image on canvas
- js index sorted
- Uncaught TypeError: jQuery(...).jqGrid is not a function
- c# parse json
- javascript set input field value
- ajax django send array
- i18n react get current language
- edit html element javascript
- jquery remove multiple class
- how to make a vertical array js
- Expected an assignment or function call and instead saw an expression
- check if date is today js
- how to get data in json format in javascript
- jquery chek radio
- useref react
- caesar cipher