Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rerender on props.url change #332

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ class Router extends Component {
return props.url!==this.props.url || props.onChange!==this.props.onChange;
}

componentWillReceiveProps(props) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can merge this with shouldComponentUpdate above.

	shouldComponentUpdate(props) {
		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;
	}

if (props.url && props.url!==this.state.url) this.routeTo(props.url) && setUrl(props.url);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passing a new URL to <Router> should not call setUrl(), since doing so will change all other Routers on the page.

}

/** Check if the given URL can be matched against any children */
canRoute(url) {
const children = toChildArray(this.props.children);
Expand Down