skip to Main Content

I’m trying to redirect a user after they click on a text with useNavigate, the route that i’m trying to use is "behind" the current route whereas useNavigate redirects "forward".

code:

<span onClick={() => navigate(`portfolio/${user}`)}
      className="text-orange-400 cursor-pointer"
              >
                {profile?.name}
              </span>

current route is http://localhost:3000/packages/PUeV5ZTXMfTRFIsoYyKi and the route is redirected to is http://localhost:3000/packages/PUeV5ZTXMfTRFIsoYyKi/portfolio/ZLPxfKnsf9sYo3l9QljPD9dfq8qM instead of http://localhost:3000/portfolio/PUeV5ZTXMfTRFIsoYyKi.

I’ve also tried onClick={() => navigate(`portfolio/${user}`, { replace: true })} but the redirect is the same.

2

Answers


  1. because this is a relative route.
    To navigate to an absolute route you need to start with /

    navigate(`/portfolio/${user}`
    
    Login or Signup to reply.
  2. <span onClick={() => navigate(/portfolio/${user})}

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search