Skip to content

Commit 2f0c5d0

Browse files
committedApr 4, 2015
Add optional onChange prop to Switcher
- Allows for a function to be provided and called when the route changes
1 parent 14aafea commit 2f0c5d0

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed
 

‎dist/switcheroo.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎modules/components/Switcher.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,15 @@ export default class Switcher extends Component {
6363
}
6464

6565
handleRouteChange(e) {
66-
var newRoute = this.getLocation();
66+
var newRoute = this.getLocation(),
67+
switchElement = this.getSwitch(newRoute);
6768
this.setState({
68-
visibleComponent: this.getSwitch(newRoute)
69+
visibleComponent: switchElement
6970
});
71+
72+
if(typeof this.props.onChange === 'function') {
73+
this.props.onChange(!!switchElement, newRoute);
74+
}
7075
}
7176

7277
render() {
@@ -80,7 +85,8 @@ Switcher.propTypes = {
8085
children: React.PropTypes.arrayOf(React.PropTypes.element).isRequired,
8186
pushState: React.PropTypes.bool,
8287
defaultHandler: React.PropTypes.func,
83-
defaultHandlerProps: React.PropTypes.object
88+
defaultHandlerProps: React.PropTypes.object,
89+
onChange: React.PropTypes.func
8490
};
8591

8692
Switcher.defaultProps = {

0 commit comments

Comments
 (0)
Please sign in to comment.