const App = () => (
<SafeAreaProvider>
<NavigationContainer theme={MyTheme} linking={linking}>
<Stack.Navigator
initialRouteName="Root"
screenOptions={{ gestureEnabled: false }}
>
<Stack.Screen
name="NotRoot"
component={NotRoot}
options={verticalConfig}
/>
</Stack.Navigator>
</NavigationContainer>
</SafeAreaProvider>
);
在此代码片段中,Root 是一个不存在的 Stack.Screen 名称,它不存在于项目源代码中的任何文件中。所以,我想知道“Root”是否有点像默认值?
最佳答案
Root
不是默认值。当您指定一个不存在的 initialRouteName
时,它的作用与您未指定 prop 时相同:它会转到第一个屏幕(路线)。
你可以在代码中看到它(GitHub),这里是相关部分:
const initialRouteName =
options.initialRouteName !== undefined &&
routeNames.includes(options.initialRouteName)
? options.initialRouteName // if initialRouteName is defined and exists
: routeNames[0]; // otherwise, go to the first one
关于reactjs - 如果 React Native 中的 React Navigation 库提供的堆栈导航器组件不存在 initialRouteName Prop 会发生什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63200145/