react js router
npm install react-router-dom
router react
npm install react-router-dom
react router
import React from "react";
import {
BrowserRouter as Router,
Switch,
Route,
Link,
useRouteMatch,
useParams
} from "react-router-dom";
export default function App() {
return (
<Router>
<div>
<ul>
<li>
<Link to="/">Home</Link>
</li>
<li>
<Link to="/about">About</Link>
</li>
<li>
<Link to="/topics">Topics</Link>
</li>
</ul>
<Switch>
<Route path="/about">
<About />
</Route>
<Route path="/topics">
<Topics />
</Route>
<Route path="/">
<Home />
</Route>
</Switch>
</div>
</Router>
);
}
function Home() {
return <h2>Home</h2>;
}
function About() {
return <h2>About</h2>;
}
function Topics() {
let match = useRouteMatch();
return (
<div>
<h2>Topics</h2>
<ul>
<li>
<Link to={`${match.url}/components`}>Components</Link>
</li>
<li>
<Link to={`${match.url}/props-v-state`}>
Props v. State
</Link>
</li>
</ul>
{/* The Topics page has its own <Switch> with more routes
that build on the /topics URL path. You can think of the
2nd <Route> here as an "index" page for all topics, or
the page that is shown when no topic is selected */}
<Switch>
<Route path={`${match.path}/:topicId`}>
<Topic />
</Route>
<Route path={match.path}>
<h3>Please select a topic.</h3>
</Route>
</Switch>
</div>
);
}
function Topic() {
let { topicId } = useParams();
return <h3>Requested topic ID: {topicId}</h3>;
}
react router
import ReactDOM from "react-dom";
import { Route, BrowserRouter as Router, Switch } from "react-router-dom";
const routing = (
<Router>
<React.StrictMode>
<Header />
<Switch>
<Route exact path="/" component={Register} />
<Route exact path="/Login" component={Login} />
<Route exact path="/Home" component={App} />
<Route path="/Logout" component={Logout} />
<Route path="/CreatePost" component={CreatePost} />
<Route path="/CreateComment" component={CreateComment} />
<Route path="/UserProfile" component={UserProfile} />
<Route path="/SearchProfile" component={SearchedProfile} />
<Route path="/follow" component={FollowDisplay} />
<Route path="/following" component={FollowingDisplay} />
</Switch>
<Footer />
</React.StrictMode>
</Router>
);
react router
import {
BrowserRouter,
Switch,
Route,
Link,
useRouteMatch,
useParams
} from "react-router-dom";
ReactDOM.render(
<BrowserRouter>
<React.StrictMode>
<Switch>
<Route exact path="/" component={React_chat_app} />
<Route exact path='/:topicId' component={component0}/>
<Route exact path="/your-url" component={component1} />
<Route component={component2} />
</Switch>
</React.StrictMode></BrowserRouter>,
document.getElementById('demo')
);
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us