zoukankan      html  css  js  c++  java
  • [React] React Router: setRouteWillLeaveHook

    setRouteWillLeaveHook provides a method for us to intercept a route change before leaving the current route.

    Route Hook with Context to works with, So if we want to handle the route hook for Home Componet, we nee to add Context for Home Component:
    class Home extends React.Component{
    
        componentWillMount(){
            this.context.router.setRouteLeaveHook(
                this.props.route,
                this.routeWillLeave
            )
        }
    
        routeWillLeave(nextLocation){
            console.log(nextLocation);
            return `Leave for next Location ${nextLocation.pathname}`;
        }
    
        render(){
            return <div><h1>Home</h1><Links></Links></div>
        }
    }
    Home.contextTypes = {
        router: React.PropTypes.object.isRequired
    };

    routeWillLeave is custom function, you can call it whatever you want, inside function, you can do the stuff you want, if you return a string, the string will show in alert dialog.

  • 相关阅读:
    Hive sql
    Hive严格模式
    Hive 分区表和分桶表
    hive
    Hive内部表与外部表区别详解
    HDFS
    Hadoop
    MySQL数据库优化
    Mysql常用存储引擎介绍
    Day12-Mysql服务日志类型及增量恢复命令
  • 原文地址:https://www.cnblogs.com/Answer1215/p/5341153.html
Copyright © 2011-2022 走看看