对request.js里面的ajax 做统一返回码处理 怎么跳到登录页呢?
export default function request (url, options) {
if (options.cross) {
return Ajax.getJSON('http://query.yahooapis.com/v1/public/yql', {
q: "select * from json where url='" + url + '?' + Ajax.param(options.data) + "'",
format: 'json'
})
} else {
return Ajax.ajax({
url: url,
method: options.method ? options.method:'get',
data: options.data ? options.data:{},
//processData: options.method === 'get',
dataType: 'JSON'
}).done((data) => {
if(data.state === 0){
return data
}else{
let msg = (data.state).toString().codeText();
message.error(msg);
//返回登录页
然后就不知道怎么回到登录页了.😓
}
})
} }
@encorehe 可以用下浏览器提供的接口进行跳转:
window.location.href = '/';
从别人的代码中看到的,居然能够传过来,dispatch const app = dva({ history: browserHistory, onError(e, dispatch) { // dispatch({type: 'app/logout'}); console.log(e); if (e.message === 'Unauthorized') { message.info('Please Login :)', 5); } else { message.error(e.message, 5); } } })
import { routerRedux } from 'dva/router'