https://github.com/ant-design/ant-design-pro/issues/7079 修复后续 又遇上两个问题
redirect 丢了?
登录成功后需要返回的页面丢了
例如,从 http://localhost:8000/#/account/settings 退出,但是 退出后 跳转到 登录页面时 redirect 没了
Safari 登录成功, 页面不跳转, 控制台也没报错
Safari 版本13.1.1 (15609.2.9.1.2)
大致原因已经找到了, 在history.push外面加个延时调转会发现,登录成功后,调用 replaceGoto(); 方法其实成功跳转到了 redirect 页面, refresh() 方法调用 也执行了 app.tsx 里面的 getInitialState()方法, 后面也会查询到 相关的登录用户信息
表面是没什么毛病的
`
// 如果没有登录,重定向到 login
if (!initialState?.currentUser?.userid && history.location.pathname !== '/user/login') {
setTimeout(() => { history.push('/user/login'); }, 5000);
}
`
但是 replaceGoto(); 调用完后,跳转到 redirect 页面, 这时 由于 getInitialState() 是个异步的,所有 onPageChange() 里面的代码居然先执行了
currentUser 这时还没取到数据,所有无情的 跳转到了 登录页面

在getInitialState中未对重定向进行处理,所以不会重新获取用户信息。页面跳转[onPageChange]时用户信息为空,所以又会重新跳转到登录页。此问题只出现在hash模式
7095
看看这个 pr
你好,我想你应该是没看明白我的意图,我现在的代码已经是最新的了,已经包含你在 app.tsx 第43行的改动
app.tsx 第43行 if (!initialState?.currentUser?.userid && history.location.pathname !== '/user/login') {
现在关键问题是 在 hash模式下,登录成功,在返回 redirect页面后,触发onPageChange时 initialState.currentUser 并没取到 当前登录者的 登录信息
在getInitialState中未对重定向进行处理,所以不会重新获取用户信息。页面跳转[onPageChange]时用户信息为空,所以又会重新跳转到登录页。此问题只出现在hash模式
你好 ”此问题只出现在hash模式“ 关键是我现在用的就是 hash模式啊, 而且也出现了这个问题,该如何解决呢,还是说这并非是个bug ?
我之所以用 hash模式,是因为 打包部署后,任何页面通过点击链接可以进页面,但是刷新页面会报 404 ,
我把我的情况讲一下,刚开始我也是message都展示登录成功了,却一直没有重定向到/welcome页面。后来发现,新版V5更改了,!initialState?.currentUser?.userid && history.location.pathname !== '/user/login',这是判断条件。currentUser是我们数据库中取得的,我们不一定有userid这个字段,所以有可能问题出现在这边。如果我们自己换成username等我们自己数据中有的,然后就成功了。
我把我的情况讲一下,刚开始我也是message都展示登录成功了,却一直没有重定向到/welcome页面。后来发现,新版V5更改了,
!initialState?.currentUser?.userid && history.location.pathname !== '/user/login',这是判断条件。currentUser是我们数据库中取得的,我们不一定有userid这个字段,所以有可能问题出现在这边。如果我们自己换成username等我们自己数据中有的,然后就成功了。
// 如果没有登录,重定向到 login
if (!initialState?.currentUser?.token&& history.location.pathname !== '/user/login'
这个我早就换了(userId换成了token),登录成功后这个token是一定有值的, 上述问题只会出现在 地址栏有 redirect 回跳页面是存在的情况,如果没有这个redirect,登录成功后,会跳到首页
if (history.location.pathname !== '/user/login') {
try {
return {
currentUser,
settings: defaultSettings,
};
} catch (error) {
history.push('/user/login');
}
}
return {
currentUser,
settings: defaultSettings,
};
我在if后面的也把currentUser给返回了,你再看看呢?
if (history.location.pathname !== '/user/login') { try { return { currentUser, settings: defaultSettings, }; } catch (error) { history.push('/user/login'); } } return { currentUser, settings: defaultSettings, };我在if后面的也把currentUser给返回了,你再看看呢?
还是不行啊
http://localhost:8000/#/user/login?redirect=http%3A%2F%2Flocalhost%3A8000%2F%23%2Fsystem%2Fapplication

我改成这样的了,但是 ....

这周会处理一下 做一个完美的方案
Most helpful comment
在getInitialState中未对重定向进行处理,所以不会重新获取用户信息。页面跳转[onPageChange]时用户信息为空,所以又会重新跳转到登录页。此问题只出现在hash模式