【问题标题】:How can i get params value when i used NavigationActions.reset使用 NavigationActions.reset 时如何获取参数值
【发布时间】:2018-08-06 17:58:05
【问题描述】:

App.js

const DrawerStack = DrawerNavigator({
  Dashboard: { screen: Dashboard},
  Pdfview: { screen: Pdfview},
  screen2: { screen: Screen2 }
})

登录.js

const resetAction = NavigationActions.reset({
  index: 0,
  actions: [
    NavigationActions.navigate({ routeName: 'DrawerStack', params: { foo: 'bar' } 
    }),  
  ],
});

我尝试在 Dashboard 上获取 params 值,但我在 Dashboard 上未定义

仪表板.js

 componentWillMount() {
   console.info(this.props.navigation.state.params)
 }

【问题讨论】:

    标签: javascript reactjs react-native navigation


    【解决方案1】:

    您应该直接导航到 Dashboard,而不是 routeName 中的 DrawerStack

    const resetAction = NavigationActions.reset({
      index: 0,
      actions: [
        NavigationActions.navigate({ routeName: 'Dashboard', params: { foo: 'bar' } 
        }),  
      ],
    });
    

    【讨论】:

    • 我用过,但如果我直接使用,我无法打开侧边菜单
    【解决方案2】:

    这应该可行。

    this.props.navigation.state.params.foo
    

    【讨论】:

      猜你喜欢
      • 2016-05-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多