Shai Kimchi Shai Kimchi - 1 year ago 98
React JSX Question

How to navigate in ReactJs singlepage app without using Link?

In react, What is the equivalent of using a

in an onClick function?
I want to create a react component inside a single page app, When a user presses anywhere on the components DOM, it has the same as the
<a href >

Answer Source

You can simply put an onClick at the top of the document if you want. The click event will bubble using normal event rules and you can access to find the origin. From there you can call window.location.href = 'some-path' to emulate the experience.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download