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)?

Avatar
Logan May

Thanks for these tuts! Really enjoyed it as an intro to React Router. I thought everything was self-explanatory, but I'm left with one question - how did you enable html snippets in your Sublime Text on .js files? Killing me writing <div> and <h1> over and over again hahaha.

Also, were you using custom es6 snippets here or did you get them from a pacakge? I'm currently using https://github.com/babel/babel-sublime-snippets for main React/JSX stuff

In reply to egghead.io
HEY, QUICK QUESTION!
Joel's Head
Why are we asking?