LeonardoGentile / react-mobx-router5

React components for routing solution using router5 and mobx
MIT License
59 stars 5 forks source link

BaseLink onClick prop should not require router #10

Closed pzmosquito closed 6 years ago

pzmosquito commented 6 years ago

according to the documentation, the BaseLink component should not require router or routerStore if onClick prop is passed in. It's giving error this.router is null on Firefox and Uncaught TypeError: Cannot read property 'navigate' of null on Chrome

LeonardoGentile commented 6 years ago

Hello, I'll take a look. Could you create a jsbin or similar to reproduce the problem?

pzmosquito commented 6 years ago

https://stackblitz.com/edit/pz-react-playground

LeonardoGentile commented 6 years ago

Thanks, in your event handler you should prevent the default browser action:

const TestBaseLink = () => {
  const handleClick = (e) => {
    e.preventDefault()
    console.log("test");

  };

  return <BaseLink onClick={handleClick}>test baselink</BaseLink>;
};

render(<TestBaseLink />, document.getElementById("root"));
pzmosquito commented 6 years ago

Uhhh... How on earth did I forget about that... Thanks for pointing it out.