React-router (0.13) + Flux - how to get an instance of the flux class in willTransitionTo?
I have a container component for all routes that need authorized access. But I need a universal lifecycle hook to ask the Flux store "is the user registered?" The problem is that it static willTransitionHook
doesn't have access to props (or context):
class AuthenticatedHandler extends React.Component {
static willTransitionTo(transition) {
// `this.props.flux` is not accessible
}
componentDidMount() {
console.log('did mount', this.props);
}
render() {
const { flux } = this.props;
return (
<FluxComponent flux={flux} connectToStores={{
user: store => ({
isLoggedIn: store.isLoggedIn(),
user: store.getUser()
})
}}>
<RouteHandler />
</FluxComponent>
);
}
}
What solution do you suggest? Use componentDidMount
+ componentDidUpdate
? Thank!
source to share
In fact, this does not exist. If you want to receive flux
as a support, you cannot rely on willTransitionTo
.
However, you can use componentWillReceiveProps
which I assume is called by React Router.
If you want to prevent the transition in the first place, I'm not sure how you should proceed.
source to share