2018-03-31 20:36:36 +13:00
|
|
|
|
2018-10-24 21:15:57 +13:00
|
|
|
import React from 'react';
|
2018-10-24 21:34:41 +13:00
|
|
|
import {Link} from 'react-router';
|
2018-03-31 20:36:36 +13:00
|
|
|
|
2018-10-25 17:00:49 +13:00
|
|
|
import * as helpers from '../helpers';
|
|
|
|
|
|
2018-10-24 21:39:08 +13:00
|
|
|
/**
|
|
|
|
|
* Extends react-router's Link but provides the ability to hook in to the navigation event
|
|
|
|
|
* which lets us scroll to the top of our <main> for a more traditional navigation experience
|
|
|
|
|
**/
|
2018-10-24 21:15:57 +13:00
|
|
|
export default class extends React.Component{
|
2018-03-31 20:36:36 +13:00
|
|
|
|
|
|
|
|
constructor(props){
|
|
|
|
|
super(props);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
handleClick(e){
|
|
|
|
|
if (!this.props.retainScroll){
|
2018-10-26 16:06:31 +13:00
|
|
|
helpers.scrollTo(this.props.scrollTo, (this.props.scrollTo));
|
2018-03-31 20:36:36 +13:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-24 21:15:57 +13:00
|
|
|
render(){
|
2018-03-31 20:36:36 +13:00
|
|
|
return (
|
|
|
|
|
<Link
|
|
|
|
|
onClick={e => this.handleClick(e)}
|
2018-10-24 21:34:41 +13:00
|
|
|
className={this.props.className ? this.props.className : null}
|
|
|
|
|
activeClassName={this.props.activeClassName}
|
2018-10-24 21:15:57 +13:00
|
|
|
to={this.props.to}>
|
2018-03-31 20:36:36 +13:00
|
|
|
{this.props.children}
|
|
|
|
|
</Link>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|