【发布时间】:2020-12-17 15:03:42
【问题描述】:
如果用户的信息尚不存在,我想将其带到个人资料页面。但是在使用 jwt 条件渲染时,initialRouteName 不起作用。也许我错过了更好的方法。有人有什么建议吗?
function ExploreNavigator() {
const jwt = useSelector(state => state.session.jwt);
const { firstName } = useSelector(state => state.user);
return (
<Stack.Navigator
headerMode="screen"
initialRouteName={firstName ? "Listings" : "Profile"}
screenOptions={{
cardStyle: {
backgroundColor: 'white',
},
}}>
{jwt ? (
<>
<Stack.Screen
name="Listings"
component={ListingsScreen}
options={{ title: 'My Studios' }}
/>
<Stack.Screen
name="Onboarding"
component={OnboardingScreen}
options={{
headerShown: false,
}}
/>
<Stack.Screen
name="Profile"
component={ProfileScreen}
options={{
headerShown: false,
}}
/>
</>
) : (
<>
<Stack.Screen
name="Sign Up"
component={SignUpScreen}
options={{
headerShown: false,
}}
/>
<Stack.Screen
name="Login"
component={LoginScreen}
options={{
headerShown: false,
}}
/>
</>
)}
</Stack.Navigator>
);
}
【问题讨论】:
标签: javascript react-native react-navigation react-navigation-v5