Hook


hook是16.8新增特性
作用:
让函数组件拥有 state,类似什么周期,ref,reduce功能
useState:模拟state

useEffect

一个参数

	useEffect(()=>{
 console.log("首次渲染与更新")
})
		//模拟
			//componentDidMount
			//componentDidUpdate
一个参数带return
	useEffect(()=>{
 console.log("首次渲染与更新")
return ()=>{console.log(首次卸载)}
})
		//模拟
		//	componentDidMount
		//	componentDidUpdate
		//return
			//componetWillUnmount
		//	componentDidUpdate
第二个参数是空数组,return
	useEffect(()=>{
 console.log("首次渲染与更新")
return ()=>{console.log(首次卸载)}
},[])
		//componentDidMount
		//componetWillUnmount
第二个参数是具体的值
useEffect(()=>{
 console.log("首次渲染与更新")
return ()=>{console.log(首次卸载)}
},[num])
		//模拟
		//	componentDidMount
			//componentDidUpdate(update只对num有用)
		//return
			//componetWillUnmount
			//componentDidUpdate(update只对num有用)

路由的参数

location 地址栏信息
1、pathname 地址
2、hash 哈希值
3、search 查询条件
4、state 数据
match
1、isExact 是否精确匹配
2、params 参数
3、url 匹配的地址
4、path Route 参数path
history
1、go 跳转历史记录
2、goBack 返回
3、goForward 前进
4、push 跳转
5、replace 跳转不留历史记录
6、length 长度
7、action 动作
8、location 同参数location

路由权限控制

核心:使用 Route 的render参数

	function PrivatePage({children}){
 return <Route render={(props)=>{
	   const component = React.cloneElement(children,props);
      // 拷贝继承
      return fakeAuth.isAuth?component:<Redirect to={{pathname:"/login",state:{from:props.location}}}/>
   }}/>
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值