e.target.href在firefox中不起作用。这仅适用于chrome。我尝试了问题的解决方案(event.target not working on Firefox),但仍然没有在firefox上工作。我还需要添加更多内容吗?
app.js
showModal(e) {
if (!e) {
e = window.event;
}
e.preventDefault();
const event = e.target || e.srcElement;
const url = event.href;
console.log('url', url, event.href);
const redirectTo = url.substring(url.lastIndexOf('/') + 1);
this.setState({ show: true });
this.context.router.transitionTo(redirectTo);
}
<Nav
showModal={(e) => this.showModal(e)}
hideModal={() => this.hideModal()}
show={this.state.show}
onHide={() => this.hideModal()}
/>
Nav.js
<button
className="btn btn-default"
onClick={(e) => props.showModal(e)}
>
<Link to={{ pathname: '/signup' }}>
{props.intl.formatMessage({ id: 'nav.registration.text' }) }
</Link>
</button>
答案 0 :(得分:1)
尝试使用run_as_udp
getAttribute()
const tgt = e.target || e.srcElement;
const url = tgt.getAttribute('href');
console.log('url', url, tgt);