Bootstrap

React中在非组件的状态下使用history

在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

 

悦读

道可道,非常道;名可名,非常名。 无名,天地之始,有名,万物之母。 故常无欲,以观其妙,常有欲,以观其徼。 此两者,同出而异名,同谓之玄,玄之又玄,众妙之门。

;