Skip to content
This repository has been archived by the owner on Oct 10, 2023. It is now read-only.

Change props.route to correct value #681

Merged
merged 1 commit into from
Jan 20, 2016
Merged

Change props.route to correct value #681

merged 1 commit into from
Jan 20, 2016

Conversation

hhhonzik
Copy link

Having props.route property inherited from parent will result in error when using routeWillLeave() in child routes (example).

@steida
Copy link
Contributor

steida commented Jan 18, 2016

Thank you! Have you tested it with current react-router 2?

@hhhonzik
Copy link
Author

@steida yeah, it works pretty well.

I tested it by adding to /src/browser/todos/Page.react.js this code:

static contextTypes = {
    router: PropTypes.object
  };
  componentDidMount() {
    this.context.router.setRouteLeaveHook(this.props.route, this.routerWillLeave.bind(this));
  }
  routerWillLeave() {
    if (this.props.todos.newTodo.title.length > 0) {
      return "Are you sure?";
    }
  }

It hooks to parent route (which is usually "/") and result in error.

@steida
Copy link
Contributor

steida commented Jan 20, 2016

Thank you!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants