【问题标题】:getUserConfirmation not working react nativegetUserConfirmation 不起作用反应本机
【发布时间】:2018-07-07 12:22:29
【问题描述】:

我正在尝试使用“react-router-native”的 getUserConfirmation 向路由添加身份验证,但永远不会调用 getUserConfirmation。我也找不到太多关于它的文档。

const getConfirmation = (message, callback) => {
  //Here i will replace below code with authentication check
  Alert.alert('Confirm', message, [
    { text: 'Cancel', onPress: () => callback(false) },
    { text: 'OK', onPress: () => callback(true) }
  ])
}

<NativeRouter getUserConfirmation={getConfirmation}>
......
</NativeRouter>

【问题讨论】:

    标签: android react-native react-router-native


    【解决方案1】:

    虽然我没有从reacttraining.com 中找到合适的例子,但经过一段时间后我找到了方法。

    const getConfirmation = (message, callback) => {
        // auth code to authenticate before entering route
        requireRouteAuth({props:{history}}, callback);
    }
    
    <NativeRouter getUserConfirmation={getConfirmation}>
        ......
        <Prompt when={true} message={location => "message"}/>
    </NativeRouter>
    

    我们需要附加组件。因为当={true}时我需要对所有路由进行身份验证。

    【讨论】:

      猜你喜欢
      • 2016-07-20
      • 2018-04-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-22
      • 1970-01-01
      相关资源
      最近更新 更多