componentDidMount() { // and/or componentDidUpdate, depending on what you're trying to do
if (!auth) {
Router.push({
pathname: '/login',
query: { from: {router.pathname} },
}))
}
}
//Then on the login page, after successful login:
handlePostLoginOk = () => {
const { router } = this.props;
if (router.query && router.query.from) {
router.push(router.query.from);
}
}