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

Include the current route in withRouter() or have a withRoute() HOC #3734

Closed
CLowbrow opened this issue Aug 17, 2016 · 4 comments
Closed

Include the current route in withRouter() or have a withRoute() HOC #3734

CLowbrow opened this issue Aug 17, 2016 · 4 comments

Comments

@CLowbrow
Copy link

I'm currently using withRouter() to create a form wrapper to prevent navigation if the form has unsaved content. I'm using setRouteLeaveHook to do this, which I am getting from the router that withRouter gives me. Unfortunately setRouteLeaveHook needs the current route, which I don't think I can get from the router object I'm passed.

There are some other ways to get the route, but it would reduce complexity if withRouter/another function provided everything I needed.

@taion
Copy link
Contributor

taion commented Aug 17, 2016

We'll get this more or less for free once we get #2172. Can't really get it at all until then.

@taion taion closed this as completed Aug 17, 2016
@pierot
Copy link

pierot commented Mar 28, 2017

@CLowbrow

There are some other ways to get the route, but it would reduce complexity if withRouter/another function provided everything I needed.

What are the other ways you found out to be able to use this.props.route?

@CLowbrow
Copy link
Author

@pierot Passing it through the component tree IIRC.

@pierot
Copy link

pierot commented Apr 18, 2017

Apparently you can use

this.props.router.setRouteLeaveHook(
  this.props.routes[this.props.routes.length - 1],
  this.routerWillLeave.bind(this)
)

It doesn't look nice, but works.

@lock lock bot locked as resolved and limited conversation to collaborators Jan 20, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants