微信瀏覽器直接訪問頁面正常,但經 snsapi_base / snsapi_userinfo 授權跳轉回來後,**所有 CSS 樣式與 JS 腳本失效**,頁面裸奔。
後端攔截器/過濾器對授權回調路徑(如 /oauth2/callback)進行了身份驗證,但錯誤地將靜態資源(.css、.js、.png 等)也納入攔截範圍,導致靜態資源請求被重定向至登入頁或返回 401/302,瀏覽器無法加載樣式/腳本。
Location,確認是否重定向至登入/錯誤頁。HandlerInterceptor、Servlet Filter、Shiro [urls] 等)。// Spring MVC Interceptor 配置
registry.addInterceptor(authInterceptor)
.addPathPatterns("/**")
.excludePathPatterns("/static/**", "/css/**", "/js/**", "/images/**", "/oauth2/callback"); // 關鍵:排除回調與靜態資源
// Shiro ini 配置範例
[urls]
/static/** = anon
/css/** = anon
/js/** = anon
/oauth2/callback = anon
/** = authc
location /static/ {
alias /var/www/app/static/;
expires 30d;
add_header Cache-Control "public";
}
授權回調端點必須匿名訪問;靜態資源永遠不應受身份驗證攔截。
微信開發中,將「靜態資源白名單」配置在攔截器最前面,可避免 90% 的「授權後樣式消失」問題。