在 angular 5 中使用 Redux 如何让浏览器在刷新时记住之前的保存状态 [英] Using Redux in angular 5 how do I get the browser to remember the previous save state on refresh

查看:16
本文介绍了在 angular 5 中使用 Redux 如何让浏览器在刷新时记住之前的保存状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,在刷新时,我失去了保存的状态.

Currently, on refresh, I loose the saved state.

我不确定是否需要在应用模块中执行任何操作.

I'm not sure if I need to do anything in the app module.

我正在使用带有 ng2-Redux 和 Redux 的 angular5、typescript、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() ]);
  }
}

我不确定是否需要在应用加载时获取状态.目前,默认的 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 或 localstorage 并在初始化时加载.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆