reactjs - react router v4 programmatically change route -
cannot seem find quality documentation on this. react router v4 documentation has information of 'history' object states mutable , should not changed. many examples have seen seem 'hacks'. insight appreciated.
i had grapple 1 while react newbie myself. while link @toddchaffee provided gives insight, this thread highlights history object automatically passed prop when have <router/> top level component. makes simpler loading history object separately , using createbrowserhistory() method.
the following worked me:
<route exact path='/' render={({history}) => <home infohandler={this.handleuserinfo} imagehandler={this.handleimage} history={history}/> }/> then inside component can:
this.props.history.push('/routeyouwanttogoto'); don't forget typecheck prop in component before export module:
home.proptypes = { history: react.proptypes.object } export default home;
Comments
Post a Comment