我正在尝试使React Router 4重定向到我的登录页面,当用户单击其NAVBAR中的"登录"按钮时,该页面可公开可用。注销功能有效,用户已记录,但是,重定向从未发生。我在这里缺少什么?
我正在使用React-Router V4和Meteorjs。
<button type="button" className="btn btn-link logout-button" onClick={() => Meteor.logout(() => (<Redirect to="/login" />))}>Logout</button>
import { Redirect } from "react-router";
class Header extends Component {
constructor(props){
super(props);
this.state = {
isLoggedIn: Meteor.userId(),
}
}
handleLogout(e){
e.preventDefault();
Meteor.logout((error) =>{
if (error) {
console.log(error.reason);
}else{
this.setState({isLoggedIn: !this.state.isLoggedIn,});
console.log("Logout successful");
}
});
}
render() {
return (
{
(this.state.isLoggedIn) &&
<Redirect to="/Login" />
}
);
}
完全像这样做应该重定向。