在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/HTML/ 在react代碼中的axios攔截器中做鏈接的轉(zhuǎn)跳

在react代碼中的axios攔截器中做鏈接的轉(zhuǎn)跳

這個是React中使用的axios攔截器,如何在攔截器中做一個react的路由轉(zhuǎn)跳?

import Axios from 'axios'

Axios.interceptors.request.use(function (config) {
  let token = window.localStorage.token;
  if (token) {
    config.headers.Authorization = `token ${token}`
  }
  return config
}, function (error) {
  return Promise.reject(error);
});

Axios.interceptors.request.use(function (config) {
  return config
}, function (error) {
  // 如何在這里加入react中的路由轉(zhuǎn)跳?
  return Promise.reject(error);
});
回答
編輯回答
黑與白

最近也遇到過 =_,=
不過我需求不是很復(fù)雜 所以暴力地直接 location.href='xxx' 跳了
坐等其它老司機回答

2017年5月3日 12:00
編輯回答
獨白
//react-router-dom (rrouter v4),如果用brower方式的話,把createHashHistory替換createBrowerHistory就可以了
import {createHashHistory} from 'history';
const history = createHashHistory();
history.push('路由地址');

//react-router v3,如果用brower方式的話,把hashHistory替換browerHistory就可以了
import {hashHistory} from 'react-router';
hashHistory.push('路由地址');
2017年2月21日 06:02