Why does my page reload every time I click a link? How can I stop it? or Is there a way to prevent un

18 Replies, 1799 Views

Page reloads on link clicks? Classic.

If you’re using vanilla JS, make sure you’re not mixing up `innerHTML` or `window.location` calls. Those can force a refresh.

Alternatively, try using `fetch()` to load content dynamically and update the DOM without a full page reload.

Here’s a quick example:
```js
document.querySelector('a').addEventListener('click', async (e) => {
e.preventDefault();
const response = await fetch('/some-url');
document.body.innerHTML = await response.text();
});
```

Messages In This Thread



Users browsing this thread: 1 Guest(s)