在react-router-dom中有Router这个包 但是Router没有history属性
Router + HashHistroy = HashRouter
Router + BrowerHistroy = BrowerRouter
安装react-router-dom时,默认会安装history包,我们可以通过这个包来自己创建history对象
具体步骤
import { createBrowserHistory } from 'history'
export const history = createBrowserHistory()
然后再<Router>中传入子组件
然后可以在响应拦截中导入使用 可以直接history.push('/login')
当token失效时 可以在js文件中使用history