react 项目学习笔记一(react-router中的history)

本文介绍了react-router中的history管理,包括createHashHistory、createBrowserHistory和createMemoryHistory三种类型。createHashHistory适用于服务器无需配置的场景,但不推荐在生产环境中使用;createBrowserHistory是推荐的浏览器历史管理方式,利用History API操作真实URL;createMemoryHistory主要用于测试和服务器渲染,不涉及地址栏变化。
摘要由CSDN通过智能技术生成

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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值