Saturday, May 5, 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

plot explanation - Why did Peaches&#39; mom hang on the tree? - Movies &amp; TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...