onEnter在React-Router中未被调用。

12 浏览
0 Comments

onEnter在React-Router中未被调用。

好吧,我受够了尝试。

onEnter方法不起作用。你知道为什么吗?

// 认证“before”过滤器
function requireAuth(nextState, replace){
  console.log("called"); // => 一点也没有被触发
  if (!isLoggedIn()) {
    replace({
      pathname: '/front'
    })
  }
}
// 渲染应用程序
render(
  
      
        
          
            
            
            
            
          
        
      
  ,
  document.getElementById("lf-app")

编辑:

当我调用onEnter={requireAuth()}时,该方法被执行,但显然这不是目的,我也无法获得所需的参数。

0