Javascript 注销后对路由器4作出反应管理路由

Javascript 注销后对路由器4作出反应管理路由,javascript,reactjs,meteor,react-router,react-router-v4,Javascript,Reactjs,Meteor,React Router,React Router V4,我是react新手,我一直在致力于使用Meteor实现基本的身份验证过程,我正在使用react路由器V4进行路由,下面是我的路由代码,以获得基本想法: const routes = ( <Router history={history}> <Switch> <Route exact path="/" component={Login} onEnter={onEnterPublicPage}/> <Route

我是react新手,我一直在致力于使用Meteor实现基本的身份验证过程,我正在使用
react路由器V4
进行路由,下面是我的路由代码,以获得基本想法:

const routes = (
  <Router history={history}>
    <Switch>
        <Route exact path="/" component={Login}  onEnter={onEnterPublicPage}/>
        <Route exact path='/signup' component={Signup} onEnter={onEnterPublicPage}/>
        <Route exact path='/links' component={Link}/>
          <Route exact path='*' component={NotFound}/>
    </Switch>
   </Router>
);  
当我登录到Root用户(即登录屏幕)时,通过注销后的代码,按下浏览器的后退按钮,我再次被重定向到主屏幕,根据预期的流程,这不应该发生。我如何处理这种情况

我试图在注销后清除浏览器历史记录,但我认为这不是实现此流程的最佳实践。任何帮助都将不胜感激。谢谢

使用
history.replace()
而不是
history.push()

为什么?

当您调用history.push界面时,它将在历史堆栈的顶部添加一个新状态(这样您可以通过单击浏览器的后退按钮转到以前的历史状态),而history.replace将用您定义的新状态替换当前历史状态

Tracker.autorun(() => {
 const isAuthenticated= !!Meteor.userId();
 console.log('isAuthenticated', isAuthenticated);
   if (isAuthenticated && isUnAuthenticatedPage){
     history.push('/links');
   }
   else if (!isAuthenticated && isAuthenticatedPage){
     history.push('/');
   }
});