history.replaceState(state, unused)
history.replaceState(state, unused, url)

// 또는
window.history.replaceState(state, unused)
window.history.replaceState(state, unused, url)
<button type="button" onclick="replacePoularTab()">인기 콘텐츠</button>
function replacePoularTab() {
    /* 초기 URL 예: https://www.example.com/ */

    // 1. 교체(변경)할 상태(State) 데이터와 URL 
    const state = { currentTab: "popular" }; // 상태(State) 데이터 
    const url = "?tab=popular"; // URL

    // 2. 현재 활성화된 방문 기록(Session History)의 상태(State) 데이터와 URL을 교체(변경)
    history.replaceState(state, "", url);

    // 3. 방문 기록 항목(entry)은 추가되지 않으면서 상태(State) 데이터와 주소창 URL 교체(변경)됨

    //    주소창 결과는 : https://www.example.com/?tab=popular

    //    상태(State) 데이터 확인 
    console.log("현재 상태 데이터:", history.state); // 출력: { currentTab: "popular" }
}
<div class="sort-buttons">
    <button type="button" onclick="changeSort('popular')">인기순</button>
    <button type="button" onclick="changeSort('latest')">최신순</button>
    <button type="button" onclick="changeSort('price_asc')">가격 낮은 순</button>
    <button type="button" onclick="changeSort('price_desc')">가격 높은 순</button>
</div>
function changeSort(sortType) {
    // 1. 현재 정렬 기준을 URL 쿼리 파라미터로 생성
    const newUrl = `?sort=${sortType}`;

    // 2. 새로운 방문 기록 항목을 추가하지 않고
    //    현재 방문 기록 항목의 상태(State)와 URL을 교체
    history.replaceState({ sort: sortType }, "", newUrl);

    console.log(`현재 정렬 기준: ${sortType}`);

    // 3. 실제 서비스에서는 이 위치에서
    //    상품 목록 갱신 또는 정렬 처리 로직을 수행합니다.
    //    예: updateProductList(sortType);
}
/* 현재 페이지 URL 예: https://www.example.com/ */
history.replaceState({}, "", "https://www.cross-example.com/"); // 다른 도메인으로의 변경