TransWikia.com

Go back and forth on react route without resetting Redux state?

Stack Overflow Asked by xaovnumwsercy on September 21, 2020

In my entry file, Ive 3 columns, I want first and last column to always be there, middle column displays different contents. I am rendering middle column as :

<Router className="middle">
    <Switch>
      <Route exact path="/" component={World}></Route>
      <Route exact path="/countries/:countryId" component={Details} ></Route>
    </Switch>
</Router>

here World component has a list of cards, where for each card on click I want to show expanded details of it, at that "/countries/:countryId" url. So in World component (where I have list of cards) I have onClick on each card which does this:

loadDetails = (countryId: string) => {
        window.location.href = `/countries/${countryId}`;
};

Now I just want to replace middle world component with this details component but WITHOUT RELOADING, RESETTING REDUX. this details component also has back button to go back to "/" url and load World component.
by doing:

onBack={() => window.history.back()}

I might have to change this route and all, please help. Whats correct way to route in this case?

Route Structure:

World("/")
    Post1
    Post2 (onclick = load post details on "/countries/:countryid")

PostDetails("/countries/:countryid")
    (onclick = go back to "/")

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP