【发布时间】:2021-01-27 12:48:02
【问题描述】:
我正在为我的项目使用 react、redux、react-router,但我遇到了一个问题。
每当我使用 history.push() 或 Link to='' 时,目标网站都不会呈现,但刷新后,一切似乎又正常了!
(将 {forcefresh: true} 添加到 ./history 似乎可以解决问题,但还有其他方法可以解决问题!)
如你所见,isSignedIn 在重定向后为空:
但是刷新后会得到true的值。
我的减速机:
import { SIGNED_IN, SIGNED_OUT } from '../actions/actionTypes';
const initialState = {
isSignedIn: null,
userInfo: null,
};
export default (state = initialState, action) => {
switch (action.type) {
case SIGNED_IN:
return { ...state, isSignedIn: true, userInfo: action.payload }; //important parts!
case SIGNED_OUT:
return { ...state, isSignedIn: false, userId: null };
default:
// return { ...state, isSignedIn: true, userInfo: action.payload };
return initialState;
}
};
【问题讨论】:
-
/client/src/components/App/App.js 用于路由器和路由设置
-
/client/scr/history.js 用于历史设置
-
您应该已经在问题本身中发布了代码。但是您的路由器设置看起来不错。确切的问题是什么?您是否无法使用
history.push转到任何路线,或者是身份验证问题,即登录完成后您看不到主页/仪表板页面? -
我在这里有视频格式的详细问题:kapwi.ng/c/njymI7Aw
标签: reactjs redux react-router