Skip to content

Commit eecfd01

Browse files
committed
增加一种特殊http状态208,当状态为208时,前端可以正常接受数据且可以跳转新的网页,跳转网页地址为header 里的Location
1 parent 3be9b50 commit eecfd01

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/app.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { ResponseError } from 'umi-request';
55
import { queryQuarkInfo, queryQuarkLayout, queryQuarkMenus, queryAccountInfo } from '@/services/quark';
66
import defaultSettings from '../config/defaultSettings';
77
import logo from './assets/logo.png';
8+
import {Response} from "express";
89

910
export async function getInitialState(): Promise<{
1011
accountInfo?: API.AccountInfo;
@@ -118,6 +119,17 @@ const errorHandler = (error: ResponseError) => {
118119

119120
export const request: RequestConfig = {
120121
errorHandler: errorHandler,
122+
responseInterceptors: [
123+
(response, options) => {
124+
if(response.status == 208){ //跳转新的url
125+
const locationUrl = response.headers.get('Location');
126+
if(locationUrl){
127+
window.open(locationUrl, response.headers.get('Target') || '_blank');
128+
}
129+
}
130+
return response;
131+
}
132+
],
121133
// 请求拦截器
122134
requestInterceptors: [
123135
(url: string, options) => {

0 commit comments

Comments
 (0)