DEV Community

Atharva Shankar Ahvad
Atharva Shankar Ahvad

Posted on

1

how to use react-router-dom, but better !!

1st step
//create react app like this ==> npx create-react-app react-router-dom

2nd step
//instal react-router-dom ==> npm i react-router-dom or yarn add react-router-dom

and then open your text editor like 'sublime text 4',

//3rd step

create file named as 'src/Navbar.js',
and use this code.

import React from 'react'
import {Link} from 'react-router-dom'

const Navbar = () => {
    return (
        <div>
            <Link to="/">Home</Link>
            <Link to="/about">About</Link>
        </div>
    )
}

export default Navbar
Enter fullscreen mode Exit fullscreen mode

create your pages like "Home ,ABout,Contact etc" I am just gonna go with "Home and About" ok :).

this is my home and about code
home :

import React from 'react'

const Home = () => {
    return (
        <div>
            <h1>This Is home page</h1>
        </div>
    )
}

export default Home
Enter fullscreen mode Exit fullscreen mode

and this is for about :

import React from 'react'

const Home = () => {
    return (
        <div>
            <h1>This Is about page</h1>
        </div>
    )
}

export default Home
Enter fullscreen mode Exit fullscreen mode

last step
//you have paste this code in app.js

import logo from './logo.svg';
import {BrowserRouter as Br,Route} from 'react-router-dom'
import Navbar from './Navbar'
import Home from './Home'
import About from './About'

function App() {
  return (
    <div className="App">

      <Br>
        <Navbar />
        <Route exact path="/">
        <Home />
      </Route>
      <Route exact path="/about">
        <About />
      </Route>
      </Br>
    </div>
  );
}

export default App;

Enter fullscreen mode Exit fullscreen mode

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay