React返回页面有多少办法 代码是什么
这篇文章给大家介绍了“React返回页面有多少方法,代码是什么”的相关知识,讲解详细,步骤过程清晰,有一定的借鉴学习价值,因此分享给大家做个参考,感兴趣的朋友接下来一起跟随小编看看吧。 React返回页面有3种方式,分别是:1、通过“this.props.history.push('/home');”方式返回到上一级页面;2、通过“this.props.history.replace('/home');”方式返回页面;3、通过“window.history.back(-1);”返回页面。 React返回页面的几种方式? react 移动端返回上一级页面的写法 移动端返回上一级页面的写法: import React, {Component} from 'react'; import './style.less'; class Header extends Component { clickBackHandler (){ // 返回到上一级页面的几种方法 //第一种 this.props.history.push('/home'); //第一种 this.props.history.replace('/home'); 但这两种方法都不好 //第三种方法,推荐使用 window.history.back(-1); } render() { return ( <div id="common-header"> {/*Header 公共头组件*/} <span className="back-icon"> <i className="icon-chevron-left" onClick={ this.clickBackHandler }></i> </span> <h1>{ this.props.title }</h1> </div> ); } } export default Header; 登录后复制 这篇关于“React返回页面有多少方法,代码是什么”的文章就介绍到这了,更多相关的内容,小编将为大家输出更多高质量的实用文章! (编辑:银川站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |