Skip to content
This repository has been archived by the owner on May 23, 2018. It is now read-only.

Commit

Permalink
fix: register node listener in componentDidMount to prevent server re…
Browse files Browse the repository at this point in the history
…ndering issues

Relates to #11
  • Loading branch information
troch committed Nov 26, 2015
1 parent a55d34a commit 46d4034
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions modules/routeNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,21 @@ function routeNode(nodeName, register = false) {
constructor(props, context) {
super(props, context);
this.router = context.router;
this.nodeListener = (toState, fromState) => this.setState({ previousRoute: fromState, route: toState });
if (!this.router.registeredPlugins.LISTENERS) {
throw new Error('[react-router5][RouteNode] missing plugin router5-listeners.');
}
this.state = {
previousRoute: null,
route: this.router.getState()
};
this.router.addNodeListener(nodeName, this.nodeListener);
}

componentDidMount() {
if (register) this.router.registerComponent(nodeName, this.refs.wrappedInstance);

if (!this.router.registeredPlugins.LISTENERS) {
throw new Error('[react-router5][RouteNode] missing plugin router5-listeners.');
}

this.nodeListener = (toState, fromState) => this.setState({ previousRoute: fromState, route: toState });
this.router.addNodeListener(nodeName, this.nodeListener);
}

componentWillUnmout() {
Expand Down

0 comments on commit 46d4034

Please sign in to comment.