The ability to reply to discussions is limited to PRO members. Want to join in the discussion? Click here to subscribe now.

React Router: setRouteWillLeaveHook

React Router: setRouteWillLeaveHook

3:29
setRouteWillLeaveHook provides a method for us to intercept a route change before leaving the current route.
Watch this lesson now
Avatar
egghead.io

setRouteWillLeaveHook provides a method for us to intercept a route change before leaving the current route.

Avatar
Zhenyang Hua

Why do we set the 'setRouteWillLeaveHook' in the componentWillMount lifecycle?

Avatar
Joseph

Great question! My personal preference is to make these types of component alterations before the component has mounted if possible. However, you could just as easily do it in componentDidMount.

In reply to Zhenyang Hua
Avatar
Arif

I wanted to clarify that it is setRouteLeaveHook not setRouteWillLeaveHook. Am I right?

Avatar
Joseph

Yes. Good catch.

In reply to Arif
Avatar
b62

What about routes with limited acces (role based)?

HEY, QUICK QUESTION!
Joel's Head
Why are we asking?