在使用redux时,路由器状态未在react-native中保持的问题可能是由于以下原因导致的:
解决这个问题的方法如下:
npm install redux-thunk
然后在创建store时将中间件应用于redux:
import { createStore, applyMiddleware } from 'redux';
import thunk from 'redux-thunk';
import rootReducer from './reducers';
const store = createStore(rootReducer, applyMiddleware(thunk));
import { connect } from 'react-redux';
const MyComponent = ({ routerState }) => {
// 使用routerState进行操作
};
const mapStateToProps = state => ({
routerState: state.router // 假设路由器状态存储在名为router的reducer中
});
export default connect(mapStateToProps)(MyComponent);
通过以上方法,可以确保在react-native中使用redux时,路由器状态能够正确保持。对于更多关于redux和react-native的信息,可以参考腾讯云的React Native产品介绍页面:React Native产品介绍。
领取专属 10元无门槛券
手把手带您无忧上云