我打算使用"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>发布于 2018-07-29 22:25:25
虽然我没有从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>我们需要附加组件。因为我需要所有路由的身份验证when={true}。
https://stackoverflow.com/questions/51223186
复制相似问题