如果用户的信息尚不存在,我想将用户带到个人资料页面。但在使用 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>
);
}
GCT1015
浮云间
相关分类