react-native - 在 redux 存储状态更改后导航到初始 Route
问题描述
每当我尝试通过更改 redux 中的购物车状态将项目添加到购物车时,它都会将我导航到堆栈导航器中的初始路由“主页”。我尝试将导航参数存储在 redux 状态,但它并没有解决我的问题。
堆栈导航器包含 3 个页面 Home->menu->detail 如果在菜单页面我将一些项目添加到 redux 状态,然后在添加后将其发送回主页。
初始化堆栈导航器
const Homenavigator = ({ navigation, props }) => {
return (
<Stack.Navigator>
<Stack.Screen
name="Home"
component={Home}
options={{
title: 'UrbanReach',
headerStyle: { backgroundColor: '#7f89df' },
headerTintColor: '#ffffff',
headerRight: (color) => (
<View style={{ right: 10, flexDirection: 'row', height: 32, bottom: 3 }}>
<Avatar
rounded
icon={{ name: 'shopping-cart' }}
size={'medium'}
containerStyle={{ right: 10, bottom: 6 }}
onPress={() => navigation.navigate('Cart')}
/>
<Badge
status="warning"
containerStyle={{ position: 'absolute', left: 15 }}
value={this.props.cart.cart.length}
badgeStyle={{ width: 1, height: 18 }}
/>
</View>
),
}}
/>
<Stack.Screen
name="Search"
component={Search}
options={{
headerStyle: { backgroundColor: '#7f89df' },
}}
/>
<Stack.Screen
name="Menu"
component={Menu}
options={{
headerStyle: { backgroundColor: '#7f89df' },
headerRight: (color) => (
<View style={{ right: 10, flexDirection: 'row', height: 32, bottom: 3 }}>
<Avatar onPress={() => navigation.navigate('Cart')} />
</View>
),
}}
/>
<Stack.Screen
name="Dishdetail"
component={Dishdetail}
options={{
title: 'Cart',
headerStyle: { backgroundColor: '#7f89df' },
headerRight: (color) => (
<View style={{ right: 10, flexDirection: 'row', height: 32, bottom: 3 }}>
<Avatar
rounded
icon={{ name: 'shopping-cart' }}
size={'medium'}
containerStyle={{ right: 10, bottom: 6 }}
onPress={() => navigation.navigate('Cart')}
/>
</View>
),
}}
/>
</Stack.Navigator>
);
};
export const cart = (state = { errMess: null, isLoading: true, cart: [] }, action) => {
switch (action.type) {
case ActionTypes.POST_CART:
return { ...state, errMess: null, isLoading: false, cart: [...state.cart, action.payload] };
default:
return state;
}
};
解决方案
推荐阅读
- racket - 字符串或字符串文字失败
- r - R packge install from GitHub - "'' does not exist in current working directory
- python - Stuck on tensorflow advanced indexing
- python - django 计算中的 0.01 差异
- c++ - 为私有结构定义两个参数的运算符重载
- kubernetes - Openshift origin oc cluster up 失败
- r - Replace for-loop by function
- partitioning - 在 Autosar 中,我们如何决定哪些 SWC/BSW 应该转到受信任的 OS 应用程序,哪些 SWC/BSW 应该转到非受信任的 OS 应用程序?
- java - 用实际的 Controller 替换 Mocked Spring Boot Controller
- android - 多风格库:“必需的 org.gradle.usage 'java-api' 并发现不兼容的值 'java-runtime'”