Saturday, 5 May 2018

reactjs - React routing on click event is not working




I am doing routing on button click event



  redirect(){

return ;

}



Its not working.



my home page- base component:



import React, { Fragment } from 'react';

render() {


const { value } = this.state;

return (

















} />



} />


} />







From my child component I have to redirect to another component,
here is my child component:



  



redirect(){


return ;

}


So but I am not getting any console error too.


Answer



is a component. So, you should use it like this.




class App extends React.Component{
state = {
isRedirect: false,
}

redirect = () => {
this.setState({ isRedirect: true });
}

render() {

return (
<>


{this.state.isRedirect ? : null }

)
}

}




OR



You can use history API



but you should add withRouter()



class App extends React.Component{

render(){
return(
<>


)
}
}

export default withRouter(App);



No comments:

Post a Comment

casting - Why wasn&#39;t Tobey Maguire in The Amazing Spider-Man? - Movies &amp; TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...