3

Let's say you click something like <Link to="/">{...}</Link> twice. You will push the "/" pathname twice onto the history.location. How would you go about preventing the same pathname being pushed onto history.location two times in a row? Is this a bad UX?

4
  • 1
    What happens in your browser when you click twice on the title of this page? I'd expect the same to happen with JS using the History API. Commented Aug 3, 2019 at 9:12
  • use this link to customize history:reacttraining.com/react-router/web/api/history Commented Aug 3, 2019 at 9:15
  • @SergiuParaschiv Exactly what my question is asking how to do? Commented Aug 3, 2019 at 10:45
  • No, you have two questions. I asked something about one of them, specifically "Is this a bad UX?". Commented Aug 3, 2019 at 12:53

1 Answer 1

4

<Link> tags in react-router-dom have a replace boolean parameter. You can check the current pathname if it matches with the incoming pathname.

<Link to="/" replace={location.pathname === "/"}>...</Link>

You can check it out https://reacttraining.com/react-router/web/api/Link/replace-bool

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.