How to Get Dom on My React Router?

There are many methods to add DOM in your React app, but the most popular is by installing the library with the name react-router-dom. As of now, there are two versions of the library: 1.0.0 and 0.15.0 (which includes React Router v6).

install react router

By Grieving GharialGrieving Gharial on Aug 20, 2020
npm install react-router-dom

Add Comment

16

import react-router-dom

By Open OxOpen Ox on Sep 19, 2020
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>;
}

Source: reactrouter.com

Add Comment

7

react router dom npm

By Joyous JaguarJoyous Jaguar on Jan 08, 2021
$ npm install --save react-router-dom

Source: www.npmjs.com

Add Comment

1

install react router

By Nervous NightingaleNervous Nightingale on Jul 24, 2020
$ npm install --save react-router

Source: www.npmjs.com

Add Comment

1

router in react-router-dom

By Testy TarsierTesty Tarsier on May 13, 2020
npm install react-router-dom
import {BrowserRouter, Switch, Route, Link} from "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>
  );
}

function Home() {
  return <h2>Home</h2>;
}

function About() {
  return <h2>About</h2>;
}

function Users() {
  return <h2>Users</h2>;
}

Add Comment

2

npm react-router-dom

By Evil EagleEvil Eagle on Jun 24, 2020
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>;
}

Source: reacttraining.com

Add Comment

2

React router is the heart and soul of react apps. When you first use React, you need to get the latest version of React router.

Shell/Bash answers related to "react router dom npm"

View All Shell/Bash queries

Shell/Bash queries related to "react router dom npm"

react router dom npm how to install react router dom with typescript react dom router react typescript react redux npm disable heroku router logs install npm ubuntu npm reinstall npm install dev dependencies only npm install --global yarn gyp error npm install install exact version npm axios npm run vue project by npm npm install Unable to authenticate, need: Bearer authorization_uri the operation was rejected by your operating system npm install install firebase npm install npm docker run npm install express syntax bash: npm: command not found nuget equivalent of npm install enzyme npm install how to install npm npm install @ngx-translate/http-loader remove all packages npm how to install all dependencies in package.json using npm reactnative protoc-gen-grpc npm npm install composition apiu npm list material ui icon npm solved - gulp : File C:\Users\Tech\AppData\Roaming\npm\gulp.ps1 cannot be loaded because running scripts is disabled on this system. Clear npm cache Npm install socket.io npm install from package.json npm install yarn global npm install styled components npm jquery How to uninstall npm package zsh command not found npm npm warn using force recommended protections disabled npm dotenv how to uninstall node and npm in windows Create React App command enzyme-adapter-react-16 find react version firebase react js how to install react js react eslint prettier react mui icons react redux vector icons react native create react app typescript install firebase in react fort awesome react github commmand for installing tailwind to react react circular progress bar react native ubuntu 20.04 react native java.lang.UnsatisfiedLinkError: couldn't find DSO to load: libfbjni.so result: 0 create react app ts create react native app typescript npx react typescript React with Typescript npx create react app typescript npx create-react-app typescript styled components react native react icons fa how to check react version

Browse Other Code Languages

CodeProZone