setRouteWillLeaveHook provides a method for us to intercept a route change before leaving the current route.
Why do we set the 'setRouteWillLeaveHook' in the componentWillMount lifecycle?
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.
I wanted to clarify that it is
setRouteWillLeaveHook. Am I right?
Yes. Good catch.
What about routes with limited acces (role based)?
Here's an article on user roles with React Router: https://hackernoon.com/role-based-authorization-in-react-c70bb7641db4