Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/427.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何将警报替换为导航。导航(“主页”)?就像在catch中打开新屏幕一样_Javascript_Reactjs_React Native - Fatal编程技术网

Javascript 如何将警报替换为导航。导航(“主页”)?就像在catch中打开新屏幕一样

Javascript 如何将警报替换为导航。导航(“主页”)?就像在catch中打开新屏幕一样,javascript,reactjs,react-native,Javascript,Reactjs,React Native,如何打开新屏幕 例如:导航。导航(“主页”) async function handleLoginWithPhonePressed() { try { ------------------------ } catch (err) { //Alert.alert(`Failed to login with phone ${err.message}`) {() => navigation.navigate('Home")} }

如何打开新屏幕

例如:导航。导航(“主页”)

async function handleLoginWithPhonePressed() {
    try { 
        ------------------------
} 
catch (err) {
      //Alert.alert(`Failed to login with phone ${err.message}`)
        {() => navigation.navigate('Home")}
    } 
}

我不太明白你的问题,因为你已经回答了自己

将Alert.Alert替换为路由器的代码

try{
 .....
}
catch{
//open the new screen or next page
//navigation.navigate("xyz")
}

异步函数handleLoginWithPhonePressed(){
试试{
const token=wait AccountKit.loginWithPhone()
如果(!令牌){
Alert.Alert('用户用电话操作取消了登录!')
回来
} 
setAuthToken(令牌)
getCurrentUser()
} 
抓住(错误){
Alert.Alert(无法使用电话${err.message}登录)
} 
}

这是正确的答案。

this.props.navigation.navigate(“主页”)


handleLoginWithPhonePressed()异步函数{
试试{
------------------------
} 
捕捉(错误){
//Alert.Alert(`使用电话${err.message}`登录失败`)
//{()=>navigation.navigate('Home')}
这个.props.navigation.navigate('Home');
} 
}

请不要附加屏幕截图,在问题中添加代码请不要上传。它们不能被复制来重现这个问题,未来的读者也无法搜索到它们,而且imgur在一些工作场所和国家被屏蔽。请以文本形式发布实际代码,以创建.async函数handleLoginWithPhonePressed(){try{const token=wait AccountKit.loginWithPhone(),如果(!token){Alert.Alert('User cancelled the login with phone action!')返回}setAuthToken(token)getCurrentUser()}catch(err){Alert.Alert(
无法使用电话登录${err.message}
)}}好的,我会试试。