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

Popular posts from this blog

How to understand 2 main() functions after using uftrace to profile the C++ program? -

c# - Update a combobox from a presenter (MVP) -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -