Cal*_*ium 1 javascript reactjs react-native react-navigation react-navigation-stack
我正在使用 React Native 和 React Navigation。我试图只让我的屏幕变成一个mode="Modal,但路线PARAMS我通过导航越来越“未定义”有错误时TypeError: undefined is not an object (evaluating 'route.params.title')。为什么会这样,我该如何解决?
我的尝试
const ModalScreen = () => (
<Modals.Navigator mode="modal">
<Modals.Screen
name="Modal"
component={Modal}
options={({ route }) => ({
title: route.params.title,
headerTransparent: true,
gestureResponseDistance: {
vertical: 500,
},
})}
/>
</Modals.Navigator>
);
const MainScreen = () => (
<Items.Navigator>
<Items.Screen
name="Main"
component={Main}
options={{ headerShown: false }}
/>
<Items.Screen name="Modal" component={ModalScreen} />
</Items.Navigator>
);
// Navigating to Modal in another file.
<TouchableOpacity
onPress={() =>
navigation.navigate("Modal", {
screen: "Modal",
title: title,
})
}
>
Run Code Online (Sandbox Code Playgroud)
当您将参数发送到嵌套导航器时,您必须像下面一样发送它
navigation.navigate('Modal', {
screen: 'Modal',
params: { title: 'title' },
})
Run Code Online (Sandbox Code Playgroud)
key params 指定它是一个参数,您可以像访问任何其他参数一样访问它。
| 归档时间: |
|
| 查看次数: |
926 次 |
| 最近记录: |