react-router 中的history
eact-router 是建立在history之上的
history 一个管理js应用session会话历史的js库。它将不同环境(浏览器,node...)的变量统一成了一个简易的API来管理历史堆栈、导航、确认跳转、以及sessions间的持续状态。
//基本 使用
import { createHistory } from 'history'
const history = createHistory()
// 当前的地址
const location = history.getCurrentLocation()
// 监听当前的地址变换
const unlisten = history.listen(location => {
console.log(location.pathname)
})
// 将新入口放入历史堆栈
history.push({
pathname: '/the/path',
search: '?a=query',
// 一些不存在url参数上面的当前url的状态值
s