react-router-dom
$ npm install --save react-router-dom
3.88
9
npm install react-router-dom
//This will Install the react-router to the required folder
//Here is a Sample Code for React Router DOM
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>
);
}
Thank you!
9
0
3.71
7
npx create-react-app demo-app
cd demo-app
Thank you!
7
0
3.8
11
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>;
}
Thank you!
11
0
4.11
9
npm install react-router-dom
Thank you!
9
0
3
1
npm install react-router
# or
yarn add react-router
Thank you!
1
0
Are there any code examples left?
New code examples in category Other
-
Other 2023-03-28 00:50:10 how to select the whole line in vscode with keyboard shortcut
-
Other 2022-03-28 00:45:24 income of a web developer
-
Other 2022-03-28 00:35:01 \pyrcc_main.py: File does not exist 'resources.qrc'
-
Other 2022-03-28 00:30:45 rick roll embed code
-
Other 2022-03-28 00:20:08 Circuit_04_Potentiometer
-
Other 2022-03-28 00:20:05 iterative power
-
Other 2022-03-28 00:15:11 flutter run all
-
Other 2022-03-28 00:10:05 when is karlson release
-
Other 2022-03-28 00:10:02 wp .htaccess example
-
Other 2022-03-28 00:00:08 bash pause in file read line by line