如果用戶的信息尚不存在,我想將用戶帶到個人資料頁面。但在使用 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> );}
React Navigation V5 InitalRouteName 不適用于條件渲染
萬千封印
2023-12-14 15:49:27