How to change URL in address bar without page reload?
Hello everyone! I'm a beginner frontend developer and I've encountered a task: I need to change the URL in the browser's address bar when a user clicks on links inside the site, but the page should not reload.
For example, I have a single-page application (SPA) with a list of articles. When a user clicks on an article title, I want the URL to change from `/` to `/article/123`, but the content should be loaded via AJAX without a full page reload. Currently I'm using regular links with `href`, and the browser just reloads the page. I tried using `window.location.href = '/article/123'`, but that also causes a reload.
Here's an example of my current code:
```javascript
// This doesn't work as expected
document.querySelector('.article-link').addEventListener('click', function(e) {
No answers yet.
Log in to leave an answer
Blogs
Serverless Functions in TypeScript: AWS Lambda from Scratch
Functional Programming in PHP: From A to Z — Complete Guide
Working with Dates and Time in Kotlin: Advanced Techniques and Examples
From Idea to Millions: How JavaScript Changes the Game in Startups