We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
本地开发的时候没有注意,因为当时地址上都带有路由或参数,但给客户的地址是一个干净地址,进去页面客户点击登录提示登录成功,但就是进不了后台。后来试了下确实也是不进入后台,然后在登录的时候打印了下initialState对象,发现是一个undefined,它当然无法调用fetchUserInfo无法跳转登录喽!
在登录页面useEffect里加个刷新,让它进入页面去调用下刷新initialState,让它不在是一个undefined
const { initialState, refresh, setInitialState } = useModel('@@initialState'); useEffect(() => { refresh(); }, []);
如果还不能解决你问题的话,直接暴力写个方法调用,不去调用ininitalState.fetchUserInfo.
const fetchUserInfo = async () => { //如果登录时候initialState 还是一个undefined 直接写一个方法调用代替它。 const userInfo = await initialState?.fetchUserInfo?.(); if (userInfo) { flushSync(() => { setInitialState((s) => ({ ...s, currentUser: userInfo, })); }); } };
The text was updated successfully, but these errors were encountered:
登录后回调中直接 flushSync(() => { setInitialState((s) => ({ ...s, currentUser: res.data.userinfo })).then(() => { const redirect = searchParams.get('redirect') || '/'; history.push(redirect); }); });
flushSync(() => { setInitialState((s) => ({ ...s, currentUser: res.data.userinfo })).then(() => { const redirect = searchParams.get('redirect') || '/'; history.push(redirect); }); });
Sorry, something went wrong.
No branches or pull requests
🥰 需求描述 | Requirements description
本地开发的时候没有注意,因为当时地址上都带有路由或参数,但给客户的地址是一个干净地址,进去页面客户点击登录提示登录成功,但就是进不了后台。后来试了下确实也是不进入后台,然后在登录的时候打印了下initialState对象,发现是一个undefined,它当然无法调用fetchUserInfo无法跳转登录喽!
🧐 解决方案 | Solution
在登录页面useEffect里加个刷新,让它进入页面去调用下刷新initialState,让它不在是一个undefined
🚑 其他信息 | Other information
如果还不能解决你问题的话,直接暴力写个方法调用,不去调用ininitalState.fetchUserInfo.
The text was updated successfully, but these errors were encountered: