我正在使用反应导航堆栈导航。第一个片段是导航代码。第二个是在我的登录页面。点击一个按钮后,它转到HomeScreen。它完美地运作。第三个代码用于从注册页面导航到主页。但我使用相同的导航代码导航到主页,但它无法正常工作。
import React from 'react';
import { StackNavigator, NavigationActions, DrawerNavigator } from 'react-navigation';
import LoginScreen from '../components/loginScreen';
import RegisterScreen from '../components/registerScreen';
import HomeScreen from "../components/HomeScreen";
const MainNavigation = StackNavigator(
{
Home: {
screen: HomeScreen,
navigationOptions: { gesturesEnabled: false }
},
Login: {
screen: LoginScreen,
navigationOptions: { gesturesEnabled: false }
},
Register: {
screen: RegisterScreen,
navigationOptions: { gesturesEnabled: false }
},
},
{
transitionConfig: () => ({ screenInterpolator: () => null }),
headerMode: "none",
initialRouteName: "Login",
navigationOptions: { gesturesEnabled: false }
}
);
export default MainNavigation;
///登录页面
var mobile_verified = true;
if (response.user.mobile_verified == mobile_verified) {
this.props.navigation.navigate("Home");
}
///注册页面
finalVerification = (e) => {
var url = `http://dev.finder-lbs.com:3050/auth/mobile_verify?code=${this.state.verificationCode}`;
// var data = {
// "verification_code": this.state.verificationCode
// };
fetch(url, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
'Accept': 'application / json',
'Authorization': 'Bearer ' + this.state.ACCESS_TOKEN
}
}).then(res => res.json())
.catch(error => console.log('Error ++++ :', error))
.then(response => {
console.log("mobile verified response---> ",response)
if ( response.status === "mobile verified")
{
console.log("ok---------------->>");
console.log("ouuuuuuuuukkkk",this.props.navigation);
this.props.navigation.navigate("Home");
}
})
}