Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Page reloads while navigating in reactJS

I’m trying to create a React web app, I have a navbar.
It was working fine actually. But it reloads every time when navigating.
I dont want the page reloads when we navigate with the navbar.

This is my navbar.

 <MDBNavbarNav fullWidth={false} className="mb-2 mb-lg-0">
    <MDBNavbarLink active aria-current="page" href="/" className="pe-5">
       Home
    </MDBNavbarLink>
    <MDBNavbarLink active href="/#" className="pe-5">
       Features
    </MDBNavbarLink>
    <MDBNavbarLink active href="#" className="pe-3">
       Contact Us
    </MDBNavbarLink>
 </MDBNavbarNav>

And my router is

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

<div className="App">
  <Router>
     <Routes>
        <Route path="/" element={<Home />}></Route>
        <Route path="/features" element={<Features />}></Route>
        <Route path="*" element={<PageNotFound />}></Route>
     </Routes>
  </Router>
</div>

What I have to do here?

>Solution :

You are using some links that are usually used for external navigation I guess.
For internal navigation, you should use the Link component, from react-router:
https://reactrouter.com/en/main/components/link
It should look like this:

<Link to={`/features`}>Features</Link>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading