I 'm Using Link tag's property to to go to hash like #1, #2,
<Link to='#1'>1</Link>
<Link to='#2'>2</Link>
When I click the link, the hash does change,but it can't trigger hashchange event.
componentDidMount() {
window.addEventListener(
'hashchange',
a => {
console.log('hashchange', a);
},
false,
);
}
So I'm wondering how can I do something when hash changes like this?
Thanks :)
I have the same problem, but according to the source of the Link component, it allows onClick functions. (https://github.com/reach/router/blob/master/src/index.js#L392)
In my case, I could solve this using such an onClick function
Agreed that the best we'd get would be to use the onClick. I've seen a few other projects take this approach and is probably the best we'll get since reach doesn't have any plans to support hashrouting
Most helpful comment
I have the same problem, but according to the source of the
Linkcomponent, it allowsonClickfunctions. (https://github.com/reach/router/blob/master/src/index.js#L392)In my case, I could solve this using such an
onClickfunction