JAVASCRIPT
router react
npm install react-router-dom
react router
//React Router 6
import Home from './Home';
import Navbar from './Navbar';
import { BrowserRouter as Router, Routes, Route } from 'react-router-dom';
import Create from './Create';
import BlogDetails from './BlogDetails';
import NotFound from './NotFound';
function App() {
return (
<Router>
<div className="App">
<Navbar />
<div className="content">
<Routes>
<Route path="/" element={<Home />} />
<Route path="/create" element={<Create />} />
<Route path="/blogs/:id" element={<BlogDetails />} />
<Route path="*" element={<NotFound />} />
</Routes>
</div>
</div>
</Router>
);
}
export default App;
react router
// APP.js Setup.........
import * as React from "react";
import { BrowserRouter, Route, Routes } from "react-router-dom";
import "./App.css";
import Home from "./Component/Home/Home";
function App() {
return (
<div className="App">
<BrowserRouter>
<Routes>
<Route path="/" element={<Home />} />
</Routes>
</BrowserRouter>
</div>
);
}
export default App;
// index.js setup
import React from "react";
import ReactDOM from "react-dom/client";
import App from "./App";
import "./index.css";
import reportWebVitals from "./reportWebVitals";
const root = ReactDOM.createRoot(document.getElementById("root"));
root.render(
<React.StrictMode>
<App />
</React.StrictMode>
);
reportWebVitals();
react router
import "./App.css";
import SignIn from "./SignIn";
import { BrowserRouter as Router, Route, Routes } from "react-router-dom";
import PrimarySearchAppBar from "./Header";
import SignUp from "./SignUp";
function App() {
return (
<Router>
<PrimarySearchAppBar />
<Routes>
{["/", "/home"].map((path) => (
<Route exact path={path} element={<Home />} />
))}
<Route path="/signin" exact element={<SignIn />} />
<Route path="/signup" exact element={<SignUp />} />
<Route exact path="*" element={<ComingSoon />} />
</Routes>
</Router>
);
}
export default App;
react router
import React from 'react';
import ReactDOM from 'react-dom';
import { Route, Link, BrowserRouter as Router } from 'react-router-dom'
import './index.css';
import App from './App';
import About from './about'
import Contact from './contact'
const routing = (
<Router>
<div>
<h1>React Router Example</h1>
<Route exact path="/" component={App} />
<Route path="/about" component={About} />
<Route path="/contact" component={Contact} />
</div>
</Router>
)
ReactDOM.render(routing, document.getElementById('root'));
react router
react router
import { BrowserRouter as Router, Routes, Route } from "react-router-dom";
return (
<>
<Router>
<>
<Routes>
<>
<Route
exact
path="/"
element={
<>
<Dashboard allFaq={allFaq} />
</>
}
/>
<Route
exact
path="/login"
element={
<>
<Login />
</>
}
/>
</>
</Routes>
</>
</Router>
</>
);
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
<Routes>
<Route path="/" element={<Home />} />
<Route path="/books" element={<BookList />} />
<Route path="/books/:id" element={<Book />} />
</Routes>
react router
import ReactDOM from "react-dom/client";
import {
BrowserRouter,
Routes,
Route,
} from "react-router-dom";
// import your route components too
const root = ReactDOM.createRoot(
document.getElementById("root")
);
root.render(
<BrowserRouter>
<Routes>
<Route path="/" element={<App />}>
<Route index element={<Home />} />
<Route path="teams" element={<Teams />}>
<Route path=":teamId" element={<Team />} />
<Route path="new" element={<NewTeamForm />} />
<Route index element={<LeagueStandings />} />
</Route>
</Route>
</Routes>
</BrowserRouter>
);
react router
import React from "react";
import { Link, Route, Switch } from "react-router-dom";
import Category from "./Category";
import Products from "./Products";
import Login from "./Login";
import PrivateRoute from "./PrivateRoute";
import "./styles.css";
const Home = () => (
<div>
<h2>Home</h2>
</div>
);
const Admin = () => (
<div>
<h2>Welcome admin!</h2>
</div>
);
export default function App() {
return (
<div>
<nav className="navbar navbar-light">
<ul className="nav navbar-nav">
<li>
<Link to="/">Home</Link>
</li>
<li>
<Link to="/category">Category</Link>
</li>
<li>
<Link to="/products">Products</Link>
</li>
<li>
<Link to="/admin">Admin area</Link>
</li>
</ul>
</nav>
<Switch>
<Route exact path="/">
<Home />
</Route>
<Route path="/category">
<Category />
</Route>
<Route path="/login">
<Login />
</Route>
<Route path="/products">
<Products />
</Route>
<PrivateRoute path="/admin" component={Admin} />
</Switch>
</div>
);
}
react router
npm install react-router-dom
# Documentation: https://reactrouter.com/
# Upgrading from prev. versions: https://reactrouter.com/docs/en/v6/upgrading/v5
react router
// npm install react-router-dom
// yarn add react-router-dom
import {
BrowserRouter as Router,
Switch,
Route,
Link
} from "react-router-dom";
react router
<Route path="/" element={<App />}>
<Route path="sales" element={<Sales />}>
<Route path="invoices" element={<Invoices />}>
<Route path=":invoice" element={<Invoice />} />
</Route>
</Route>
</Route>
reactjs router
yarn add react-router-dom
npm install react-router-dom
router react
npm install -g create-react-app
create-react-app demo-app
cd demo-app