From 89061e1c71956669340c4b9d2085e0059da1b513 Mon Sep 17 00:00:00 2001 From: Eric Peresse Date: Sun, 11 Aug 2019 08:59:30 +0200 Subject: [PATCH 1/2] rerender on props.url change --- src/index.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/index.js b/src/index.js index a34bd2d3..90fb85f1 100644 --- a/src/index.js +++ b/src/index.js @@ -160,6 +160,10 @@ class Router extends Component { return props.url!==this.props.url || props.onChange!==this.props.onChange; } + componentWillReceiveProps(props) { + if (props.url && props.url!==this.state.url) this.routeTo(props.url) && setUrl(props.url); + } + /** Check if the given URL can be matched against any children */ canRoute(url) { const children = toChildArray(this.props.children); From 0e1601a691d2dcc9fa93e1215c95bccb7ae01efb Mon Sep 17 00:00:00 2001 From: Eric Peresse Date: Mon, 21 Oct 2019 11:44:24 +0200 Subject: [PATCH 2/2] moved url prop update logic to shouldComponentUpdate --- src/index.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/index.js b/src/index.js index 865323e3..6a661a55 100644 --- a/src/index.js +++ b/src/index.js @@ -156,12 +156,8 @@ class Router extends Component { } shouldComponentUpdate(props) { - if (props.static!==true) return true; - return props.url!==this.props.url || props.onChange!==this.props.onChange; - } - - componentWillReceiveProps(props) { - if (props.url && props.url!==this.state.url) this.routeTo(props.url) && setUrl(props.url); + if (props.url && props.url!==this.state.url) this.routeTo(props.url); + return !props.static || props.url!=this.props.url || props.onChange!=this.props.onChange; } /** Check if the given URL can be matched against any children */