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

Commit 46d4034

Browse files
committed
fix: register node listener in componentDidMount to prevent server rendering issues
Relates to #11
1 parent a55d34a commit 46d4034

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

modules/routeNode.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,21 @@ function routeNode(nodeName, register = false) {
1010
constructor(props, context) {
1111
super(props, context);
1212
this.router = context.router;
13-
this.nodeListener = (toState, fromState) => this.setState({ previousRoute: fromState, route: toState });
14-
if (!this.router.registeredPlugins.LISTENERS) {
15-
throw new Error('[react-router5][RouteNode] missing plugin router5-listeners.');
16-
}
1713
this.state = {
1814
previousRoute: null,
1915
route: this.router.getState()
2016
};
21-
this.router.addNodeListener(nodeName, this.nodeListener);
2217
}
2318

2419
componentDidMount() {
2520
if (register) this.router.registerComponent(nodeName, this.refs.wrappedInstance);
21+
22+
if (!this.router.registeredPlugins.LISTENERS) {
23+
throw new Error('[react-router5][RouteNode] missing plugin router5-listeners.');
24+
}
25+
26+
this.nodeListener = (toState, fromState) => this.setState({ previousRoute: fromState, route: toState });
27+
this.router.addNodeListener(nodeName, this.nodeListener);
2628
}
2729

2830
componentWillUnmout() {

0 commit comments

Comments
 (0)