Reputation: 9492
Using NextJS router my website is receiving the same image.
// user/[id]
const router = useRouter();
const { id } = router.query as {
id: string;
};
return (
<div>
<p>{id}</p>
<img src={...}/>
</div>
)
On page user/1
the image is correct. Clicking a button on page to user/2
displays the correct image for 2. When clicking back
on the browser or window.history.back()
to user/1
the image is still of user 2.
How do I do a complete refresh on the page to ensure the cache isn't used?
Upvotes: 1
Views: 167
Reputation: 57
Setting a unique key for the img tag based on the page id will solve it.
<img key={id} src={...}/>
Upvotes: 1