Home > Blockchain >  How to use Link to replace() rather than push() to the react router
How to use Link to replace() rather than push() to the react router

Time:12-26

I have a navigation bar:

<div>
           <span>
            <NavLink to="home">Home</NavLink>
          </span>
          <span>
            <NavLink to="find">Find</NavLink>
          </span>
</div>

<Routes>
        <Route path="/home" element={<Home />} />
        <Route path="/find" element={<Find />} />
</Routes>

Inside of home Component I am trying to do this:

         <button>
            <Link to="find">
              Find
            </Link>
          </button>

But the problem is whenever I click on Find in url it passes home/find but I dont want to push this route like this I want it to be just /find

Current output: localhost:3000/home/find
Expexted output: localhost:3000/find

CodePudding user response:

missing the /

<Link to="/find">
  • Related