Saturday 9 June 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

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...