import * as React from 'react' ; const Confirm = ( props ) => ( < > < em onClick = { props . pass } > 同意 < /em> < em onClick = { props . stop } > 拒绝 < /em> < />); export default class About extends React . Component < any > { public static getInitialProps ( ctx ) { return { id : ctx . match . params . id , qid : ctx . query . id } ; } public static routeWillLeave ( to , from , next ) { console . log ( 'routeWillLeave' ) ; ( window as any ) . jestMock && ( window as any ) . jestMock ( ) ; if ( from . query . id === '1' && to . query . id === '2' ) { next ( < Confirm />); } else if ( from . query . id === '2' && to . query . id === '3' ) { next ( < p > 同意 < /p>); } else if ( from . query . id === '2' && to . query . id === '4' ) { next ( '/about/4' ) ; } else if ( from . location . pathname === '/about/4' && to . query . id == '4' ) { next ( true ) ; } else if ( from . query . id === '4' && to . query . id === '5' ) { next ( false ) ; } else if ( from . query . id === '4' && to . query . id === '6' ) { next ( { pathname : '/about/6' } ) ; } else if ( from . location . pathname === '/about/6' && to . query . id === '7' ) { next ( { pathname : '/about/1' , replace : true } ) ; } else if ( from . location . pathname === '/about/1' && to . query . id === '8' ) { next ( ( ) => { } ) ; } else { next ( ) ; } } public static routeDidUpdate ( to , from , data ) { console . warn ( to . location . pathname ) ; console . warn ( to . location . search ) ; if ( arguments . length === 3 ) { ( window as any ) . routeDidUpdateArgs && ( window as any ) . routeDidUpdateArgs ( ) ; } console . log ( 'routeDidUpdate' ) ; ( window as any ) . jestMock && ( window as any ) . jestMock ( ) ; } public render ( ) { return ( < div > < p > hello about { this . props . id } { this . props . qid } < /p> < /div>); } }