1

I am using Reactjs to make pagination and problem I got is that I cannot back to home page if currentPage is changed.

My code structure of Body component like this:

componentDidMount() {
 .....
}
componentDidUpdate() {
 ....
}
onPageChanged() {
.... 
   this.setState({
        pageChanged: true,
        currentPage: currentPage //1,2,3...
   });
}

render(){
  return(..)
}

When onePageChanged if I click to Home route, It does not reflect anything. How I can set componentDidUpdate to return the first page if I click on Header?

my Header component:

<h1 className="site-title">
   <Link to={CelestialSettings.path}>My Website</Link>
</h1>

I am thinking about using onClick on Header component like this:

<Link onClick={backhomepage()}>My Website</Link>

but I do not know how use.

Any suggestion? Thank you so much.

Hai Tien
  • 2,215
  • 5
  • 28
  • 44
  • 1
    Are you using `react-router-dom`? Can you add all your code logic to the question? – Dinesh Pandiyan Nov 24 '18 at 05:09
  • Hi @DineshPandiyan. Yes. I am using react-router-dom. Sorry the code is so long so I cannot post here. I just want to know is possible to call function to return homepage from `Header` – Hai Tien Nov 24 '18 at 05:43
  • 1
    You need to programmatically navigate to a new page. You can use `history.push()` for your case. Take a look at this answer - [programmatically-navigate-using-react-router-v4](https://stackoverflow.com/questions/42123261/programmatically-navigate-using-react-router-v4) – Dinesh Pandiyan Nov 24 '18 at 05:48

0 Answers0