I have a list page, where all games from my games.json file are displayed.
This is what that looks like in GameListPage.tsx:
<IonList>
{gamesJson.map((game) => (
<IonItem
routerLink={
game.software_used ?
/games/id/${game.steam_appid}` : '/games'
}
key={game.steam_appid}
>
<IonThumbnail slot="start">
<img alt={game.name} src={game.header_image} />
</IonThumbnail>
<IonLabel>
<h2>{game.name}</h2>
<p>{game.developer}</p>
</IonLabel>
</IonItem>
))}
</IonList>
When you click on the item, you are redirected to the game details page. However, you are only redirected after refreshing the page.
This is what my IonReactRouter
looks like in App.tsx:
<IonReactRouter>
<IonTabs>
<IonRouterOutlet>
<Route exact path="/games">
<GameListPage />
</Route>
<Route path="/games/id/:id">
<GameDetailsPage />
</Route>
<Route exact path="/software">
<SoftwareListPage />
</Route>
<Route exact path="/">
<Redirect to="/games" />
</Route>
</IonRouterOutlet>
<IonTabBar slot="bottom">
<IonTabButton tab="games" href="/games">
<IonIcon aria-hidden="true" icon={triangle} />
<IonLabel>Games</IonLabel>
</IonTabButton>
<IonTabButton tab="software" href="/software">
<IonIcon aria-hidden="true" icon={ellipse} />
<IonLabel>Software</IonLabel>
</IonTabButton>
</IonTabBar>
</IonTabs>
</IonReactRouter>
How can I fix this issue so that the page is instantly loaded after clicking on the item in the list?
2
Answers
react-router-dom
npm library<Link>
component with the (to) attribute<Link to={_link distination_}>{children}</Link>
for example, it will be like this (indeed after you set your routers well)
This way you will use the react routing and the page will not rerender.
For what it’s worth I believe I once solved a similar issue by rendering the routes into the
Switch
component exported fromreact-router-dom
. TheIonContent
component may or may not be needed in your case, but including it here as an example: