我在React-Navigation中遇到问题,无法从后循环循环退出。
我在App.js中定义了一个StackNavigator
const AppNavigator = createAppContainer(createStackNavigator(
{
Splash: { screen: Splash },
Home: { screen: Home, backBehavior: true },
Servers: { screen: Servers },
Settings: { screen: Settings },
Events: { screen: Events },
Traffic: { screen: Traffic },
Friends: { screen: Friends },
UserProfile: { screen: UserProfile },
[...]
})
场景:
this.props.navigation.navigate('Friends')
导航到朋友屏幕要使用“好友”导航到单个个人资料详细信息,请使用
goToProfile(steamUser)
{
this.navigateWithParams('UserProfile', { steamID: steamUser.steamid, goBack: 'Friends' })
}
navigateWithParams(routeName, params)
{
/*var navigationParams = {
routeName: routeName,
params: params,
key: routeName + uuid()
};
console.warn(navigationParams);
//this.props.navigation.push({ routeName: routeName, params: params, key: uuid() });
const navigateAction = NavigationActions.navigate(navigationParams);
this.props.navigation.dispatch(navigateAction);*/
this.props.navigation.push(routeName, params);
}
(对不起,我已经尝试了许多解决方案)。
要导航回去,我编写了一个实用程序功能来管理带参数的屏幕:
navigateBack() {
if (this.props.navigation.state && this.props.navigation.state.params && this.props.navigation.state.params.goBack)
{
if (this.props.navigation.state.params.goBackParams)
this.props.navigation.navigate(this.props.navigation.state.params.goBack, this.props.navigation.state.params.goBackParams);
else
this.props.navigation.navigate(this.props.navigation.state.params.goBack);
}
else
{
this.props.navigation.goBack();
}
}
我尝试注释if并仅保留this.props.navigation.goBack(),结果相同。
最后一步是我正在考虑的错误。
我想回到首页,因为对我来说导航堆栈应该是:
主页>朋友>用户个人资料(带参数)>主页
我在冤What什么?也许我正在使用wronly .navigate或.push或.goBack?
希望有人可以。
谢谢