如何在React-Navigation/Drawer中实现'goBack' 6
How to achieve 'goBack' in React-Navigation/Drawer 6
我在 React-navigation/drawer 6 中实现 'goBack' 功能时遇到问题(“@react-navigation/drawer”:“^6.1.4”,准确地说)。
我在react-navigation/drawer5中用下面的代码完美实现了:
<Drawer.Navigator>
<Drawer.Screen
....
options={{
header: ({ scene }) => {
const { options } = scene.descriptor;
const title = options.headerTitle;
return (
<MyHeader
title={title}
iconName={"menu"}
goback={
()=>scene.descriptor.navigation.goBack()}
/>
);
},
}}
/>
</Drawer.Navigator>
react-navigation/drawer 6 的相同修改代码(如下所示)将带我回到初始屏幕(而不是之前的屏幕)。它还会给出警告和错误消息。
<Drawer.Navigator>
<Drawer.Screen
....
options={{
header: ({ navigation, route, options }) => {
const title = getHeaderTitle(options, route.name);
return (
<MyHeader
title={title}
iconName={"menu"}
goback={
()=>navigation.goBack()}
/>
);
},
}}
/>
</Drawer.Navigator>
拜托,我怎样才能在 react-navigation/drawer 6 中实现这个 'goBack'?
您需要指定backBehavior
<Drawer.Navigator backBehavior="history">
升级文档时请阅读升级指南这些更改:https://reactnavigation.org/docs/upgrading-from-5.x/#the-default-value-for-backbehavior-is-now-firstroute-for-tabs-and-drawer
我在 React-navigation/drawer 6 中实现 'goBack' 功能时遇到问题(“@react-navigation/drawer”:“^6.1.4”,准确地说)。
我在react-navigation/drawer5中用下面的代码完美实现了:
<Drawer.Navigator>
<Drawer.Screen
....
options={{
header: ({ scene }) => {
const { options } = scene.descriptor;
const title = options.headerTitle;
return (
<MyHeader
title={title}
iconName={"menu"}
goback={
()=>scene.descriptor.navigation.goBack()}
/>
);
},
}}
/>
</Drawer.Navigator>
react-navigation/drawer 6 的相同修改代码(如下所示)将带我回到初始屏幕(而不是之前的屏幕)。它还会给出警告和错误消息。
<Drawer.Navigator>
<Drawer.Screen
....
options={{
header: ({ navigation, route, options }) => {
const title = getHeaderTitle(options, route.name);
return (
<MyHeader
title={title}
iconName={"menu"}
goback={
()=>navigation.goBack()}
/>
);
},
}}
/>
</Drawer.Navigator>
拜托,我怎样才能在 react-navigation/drawer 6 中实现这个 'goBack'?
您需要指定backBehavior
<Drawer.Navigator backBehavior="history">
升级文档时请阅读升级指南这些更改:https://reactnavigation.org/docs/upgrading-from-5.x/#the-default-value-for-backbehavior-is-now-firstroute-for-tabs-and-drawer