
react-router
Passion is Energy
这个作者很懒,什么都没留下…
展开
-
为什么不在 constructor或者 componentWillMount 请求数据?
为什么不在 constructor?官网说明,在 concurrent 模式下, constructor 会被执行多次!constructor 是用于初始化 class 的初始状态,不建议有副作用的逻辑在里面!面向对象里, class 的 constructor 是用于存放一些具有确定性的属性和方法!为什么不在 componentWillMount?如果服务端渲染,componentWillMount 会被服务端渲染一次,前端渲染一次。componentWillMount 这个生命函数钩子在原创 2021-10-10 19:13:27 · 624 阅读 · 0 评论 -
Token 的失效处理和无感刷新的两种方法
1. 通过 timeStamp, 超过时间,就用 refresh-token去更换 新的 token — 基于 vue 实现在路由前置守卫处理定义路由前置守卫router.beforeEach((to, from, next) => { next()})登录成功存时间戳import { setItem } from '@/utils/storage.js'setItem('TOKENDATE', Date.now())进入路由之前进行判断tokenimport { get原创 2021-09-13 23:32:32 · 4014 阅读 · 2 评论 -
在普通 js文件中,需要使用 history, 遇到的两个坑!!!
1. 在 安装 react-router-dom 的时候,自带安装 history 包,直接 import 即可history:object1.1 起因:在看文档的时候,看到 demo 中 import 了 history 包。于是乎,我就先去 yarn add history 。 没想到,在点击页面的时候,页面先是空白的,必须手动刷新,才会出现正常的当前页面内容。1.2 处理:yarn remove react-router-domyarn add react-router-dom1原创 2021-09-13 23:00:01 · 836 阅读 · 0 评论 -
history.replace() Vs history.push() 区别
1. history 原理用户访问的页面地址会保存到一个栈中 (LIFO 后进先出)2. history 的 go()/home ==> /home/qa ===> /home/videohistory.go(-1) // 返回前一个页面,history.go(-2) 往前翻回第二个页面history.go(1) // 前进一个页面3. history 的 replace() 和 push()History Push: The user can go forward原创 2021-09-13 12:16:23 · 11652 阅读 · 0 评论 -
封装的组件,没有通过 Route 标签包裹,如何取得 history
一. 场景1. 目前,有两个页面,Home and Login, 只有它们两个被 <route> 标签包裹<Router> <div className="App"> <Suspense fallback={<div>...loading</div>}> <Switch> &l原创 2021-09-09 11:02:11 · 256 阅读 · 0 评论