在angular 5中使用Redux如何使浏览器记住刷新时的先前保存状态 [英] Using Redux in angular 5 how do I get the browser to remember the previous save state on refresh
问题描述
当前,在刷新时,我会松开保存的状态.
Currently, on refresh, I loose the saved state.
我不确定是否需要在 app模块中执行任何操作.
I'm not sure if I need to do anything in the app module.
我使用的是angular5,打字稿,带有 ng2-Redux和Redux 的webpack.
I'm using angular5, typescript, webpack with ng2-Redux and Redux.
这是我当前的应用模块类:
export class AppModule {
constructor(ngRedux: NgRedux<IAppState>) {
ngRedux.configureStore(rootReducer, INITIAL_APP_STATE, [ createLogger() ]);
}
}
我不确定是否需要在应用程序加载时获取getState. 当前,始终始终设置默认的INITIAL_APP_STATE,从而失去了浏览器内存中的存储状态.
I'm not sure if I need to getState on load of the app. Currently the default INITIAL_APP_STATE is always set thus loosing the stores state in the browsers memory.
推荐答案
这是redux的正常行为,您可以尝试将状态保存到Cookie或本地存储中,并在初始化时加载它.
It's the normal behavior of the redux, you can try to save your state to a cookie or localstorage and load it on initialisation.
要在每次更新后将状态保存到本地存储中,您需要创建一个全局化简器来保存状态. (如果您的状态较大,则可能会占用大量CPU)
To save state to local storage after each update, you need to create a global reducer that saves the state. (it can cost a lots of CPU if you have a big state)
这篇关于在angular 5中使用Redux如何使浏览器记住刷新时的先前保存状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!