How can I redirect after successful post
Diallo Mamadou Pathé

Diallo Mamadou Pathé @pathus90

About: Software Engineer | Passionate about F1, Startups & Tech | Exploring the intersections of innovation & societal impact

Location:
Paris
Joined:
Jun 26, 2019

How can I redirect after successful post

Publish Date: Mar 28 '20
5 2

Comments 2 total

  • Gurupal Singh
    Gurupal SinghMar 28, 2020

    Use BrowserRouter which uses HTML5 history API (pushState, replaceState and the popstate event) to keep your UI in sync with the URL.

    After successful API request you can do

    this.props.history.push("/path-to-redirect");

    . Make sure to wrap your component with --> withRouter.

  • FoodBite
    FoodBiteMar 28, 2020

    I'm assuming you're not using router dom, on parent component or the component you want to redirect use state like {renderPost:false} initially,then use method to toggle the state which renders post component , in post component pass a function as prop which makes {renderPost :false} in parent component, so whenever you want to redirect you can use method from props like this.props.Redirect()

Add comment