I have the following redux
configuration in react-native
using react-native-router-flux
and redux-persist
. I want to retrieve the last current route on refresh, however the route stack is being overwritten on reload.
This is the reducers/index.js
file
import { combineReducers, createStore, applyMiddleware, compose } from 'redux'
import { persistStore, autoRehydrate } from 'redux-persist'
import { AsyncStorage } from 'react-native'
import logger from 'redux-logger'
import { startServices } from '../services'
import navigation from './navigation'
import devices from './devices'
import rooms from './rooms'
import { ActionConst } from 'react-native-router-flux'
function routes (state = {scene: {}}, action = {}) {
switch (action.type) {
// focus action is dispatched when a new screen comes into focus
case ActionConst.FOCUS:
return {
...state,
scene: action.scene,
};
// ...other actions
default:
return state;
}
}
export const reducers = combineReducers({
routes,
navigation,
devices,
rooms
})
const middleware = [logger()]
const store = createStore(
reducers,
compose(
autoRehydrate(),
applyMiddleware(...middleware)
)
)
persistStore(store, {storage: AsyncStorage}, function onStoreRehydrate () {
startServices()
})
export { store, reducers }
EDIT: This is the index.js
with it's Provider and scenes:
import React, { Component } from 'react'
import { store } from './reducers'
import { Provider, connect } from 'react-redux'
import { Router, Scene, Actions } from 'react-native-router-flux';
import Home from './containers/home'
import Login from './containers/login'
import Device from './containers/device'
const scenes = Actions.create(
<Scene key="root">
<Scene key="home" component={Home} />
<Scene key="login" component={Login} />
<Scene key="device" component={Device} />
</Scene>
)
const RouterWithRedux = connect()(Router)
export default class EntryPoint extends Component {
render () {
return (
<Provider store={store}>
<RouterWithRedux scenes={scenes} />
</Provider>
)
}
}