fix(auth/user-center): 修复个人登录回跳并兼容旧入口

This commit is contained in:
zhanjunhao
2026-12-01 16:07:31 +08:00
parent 7e89edda5b
commit cd6eae5ed9
5 changed files with 60 additions and 42 deletions
+24 -35
View File
@@ -6,12 +6,7 @@ import {
} from './helpers/miniProgram';
import Loading from './components/common/ui/Loading';
import { CenterRouteLoading } from './components/layout/components/CenterSidebarLoading';
import {
AuthRedirect,
PrivateRoute,
AdminRoute,
RootRoute,
} from './helpers/auth';
import { AuthRedirect, PrivateRoute, RootRoute } from './helpers/auth';
import { PermRoute, ConsoleRoute, ConsoleIndexRoute } from './authz';
import NotFound from './pages/NotFound';
import Forbidden from './pages/Forbidden';
@@ -76,9 +71,6 @@ const Task = lazy(() => import('./pages/Task'));
const ModelPage = lazy(() => import('./pages/Model'));
const Playground = lazy(() => import('./pages/Playground'));
const MonitorCenter = lazy(() => import('./pages/MonitorCenter'));
const PersonalSetting = lazy(
() => import('./components/settings/PersonalSetting'),
);
const Setup = lazy(() => import('./pages/Setup'));
const Analytics = lazy(() => import('./pages/Analytics'));
const SmartRouter = lazy(() => import('./pages/SmartRouter'));
@@ -145,20 +137,10 @@ const PricingLegacyRedirect = () => {
);
};
// 密钥管理旧路径 /key-management → /user-center/key-management,同样保留 query/hash
// (如创作台 ?from=creation_studio 埋点来源、旧书签与登录回跳带参)
const KeyManagementLegacyRedirect = () => {
const location = useLocation();
return (
<Navigate
to={{
pathname: '/user-center/key-management',
search: location.search,
hash: location.hash,
}}
replace
/>
);
// 用户中心旧地址保留登录回跳、分享链接及书签中的参数。
const UserCenterLegacyRedirect = ({ to }) => {
const { search, hash } = useLocation();
return <Navigate to={{ pathname: to, search, hash }} replace />;
};
function App() {
@@ -726,16 +708,6 @@ function App() {
</ConsoleRoute>
}
/>
<Route
path='/console/personal'
element={
<AdminRoute>
<Suspense fallback={<Loading></Loading>} key={location.pathname}>
<PersonalSetting />
</Suspense>
</AdminRoute>
}
/>
<Route
path='/console/topup'
element={
@@ -820,10 +792,27 @@ function App() {
)
}
/>
{/* 密钥管理归入用户中心路径;旧地址保留为重定向(旧链接、登录回跳、书签) */}
<Route
path='/console/personal'
element={
<PrivateRoute>
<UserCenterLegacyRedirect to='/user-center/settings' />
</PrivateRoute>
}
/>
<Route
path='/user/center'
element={
<PrivateRoute>
<UserCenterLegacyRedirect to='/user-center' />
</PrivateRoute>
}
/>
<Route
path='/key-management'
element={<KeyManagementLegacyRedirect />}
element={
<UserCenterLegacyRedirect to='/user-center/key-management' />
}
/>
<Route
path='/user-center/key-management'
+2 -2
View File
@@ -36,7 +36,7 @@ const OAuth2Callback = (props) => {
if (message === 'bind') {
showSuccess(t('绑定成功!'));
navigate('/console/personal');
navigate('/user/center', { replace: true });
return;
}
@@ -74,7 +74,7 @@ const OAuth2Callback = (props) => {
// 参数缺失直接返回
if (!code) {
showError(t('未获取到授权码'));
navigate('/console/personal');
navigate('/user/center', { replace: true });
return;
}
+8 -2
View File
@@ -137,8 +137,9 @@ const UserCenter = ({ keyManagementMode = false }) => {
userGroup,
firstRoute,
} = useUserCenterRoutes();
const { pathname, search, hash } = useLocation();
// 仅用于页面外壳的样式标识(看板与子页面底色不同),不参与路由判断
const ucRoute = useLocation().pathname.split('/')[2] || 'dashboard';
const ucRoute = pathname.split('/')[2] || 'dashboard';
// 跑马灯公告是否存在(用于动态计算顶部间距)
const { visible: hasMarquee } = useMarquee();
@@ -177,7 +178,12 @@ const UserCenter = ({ keyManagementMode = false }) => {
<Routes>
<Route
path='/'
element={<Navigate to={firstVisibleRoute} replace />}
element={
<Navigate
to={{ pathname: firstVisibleRoute, search, hash }}
replace
/>
}
/>
<Route
path='dashboard'