Procházet zdrojové kódy

fix: SSO回调hash路由重定向使用window.location.href

kinglee před 1 týdnem
rodič
revize
54c6ee712b
1 změnil soubory, kde provedl 10 přidání a 0 odebrání
  1. 10 0
      src/app.tsx

+ 10 - 0
src/app.tsx

@@ -40,6 +40,16 @@ export async function getInitialState(): Promise<{
   currentUser?: Global.UserInfo;
   pluginData?: Record<string, any>;
 }> {
+  // SSO 回调 URL 修复:SSO 平台 redirect_uri 不带 #,
+  // UmiJS hash 路由初始化时会追加 #/login,导致 URL 变成
+  // /auth/callback?code=xxx#/login,渲染登录页而非回调页。
+  // 在 getInitialState 最开头用 window.location.href 做硬重定向,
+  // 浏览器执行时保持当前 host:port 不变。
+  if (window.location.pathname.startsWith('/auth/callback') && !window.location.hash.startsWith('#/auth/callback')) {
+    const search = window.location.search;
+    window.location.href = '/#/auth/callback' + search;
+  }
+
   const { location } = history;
 
   // In open-source builds the promise resolves immediately.