Friday, August 30, 2019

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

hard drive - Leaving bad sectors in unformatted partition?

Laptop was acting really weird, and copy and seek times were really slow, so I decided to scan the hard drive surface. I have a couple hundr...