小编Ale*_*uil的帖子

使用 nextJS 在路由更改时自行重置 Redux 存储

你好,我遇到了 Redux 和 NextJS 的问题,当我使用 API 登录我的应用程序时,我的用户信息完美地存储在 redux 存储中,感谢 reduxApiMiddleware,但是当我重新加载浏览器或更改路由时我的商店回到它的初始状态:/。

我真的没有找到解决这个问题的方法,我尝试使用 redux-persist 但没有任何效果

这是我的 _app.js 文件:

 // pages/_app.jsx
import React from "react";
import {createStore,applyMiddleware} from "redux";
import {Provider} from "react-redux";
import App,{Container} from "next/app";
import withRedux from "next-redux-wrapper";
import reducer from '../redux/reducers/index'
import { apiMiddleware } from "redux-api-middleware";
import { PersistGate } from 'redux-persist/integration/react';


/**
* @param {object} initialState The store's initial state (on the client side, the state of the server-side store is passed here)
* @param {boolean} options.isServer …
Run Code Online (Sandbox Code Playgroud)

reactjs redux react-redux next.js

8
推荐指数
1
解决办法
1161
查看次数

标签 统计

next.js ×1

react-redux ×1

reactjs ×1

redux ×1