如何在getStateForAction

时间:2019-04-15 02:20:07

标签: javascript react-native react-navigation

该应用有多个页面,有些页面需要登录才能打开,有些则不需要。我想要 在路由配置中配置是否需要登录的每个页面。但我无法获得init参数 getstateforaction

|反应导航| 3.3.2 |反应本机| 0.58.6 |节点| 11.9.0 | npm或纱| npm

const MainNavigator = createStackNavigator({
  Home,
  Settings: createStackNavigator({ Setting: {
     screen: Setting,
     params: { auth : true}
  }})

const defaultGetStateForAction = MainNavigator.router.getStateForAction

MainNavigator.router.getStateForAction = (action, lastState) => {
  console.log(action)  //print   { type:  "Navigation/NAVIGATE" , routeName: "Setting"}
  return defaultGetStateForAction(action, lastState)
}

0 个答案:

没有答案