URLを操作
URL各要素取得
let url = new URL(location);
let href = location.href;
let host = location.hostname;
let port = location.port;
let path = location.pathname;
let query = location.search;
let protocol = location.protocol;
ブラウザー履歴エントリに state, title, url をセット
画面に更新をかけたくはない。
けどURLを更新したいというときに使ってます。
const url = new URL(window.location);
url.searchParams.set('foo', 'bar');
window.history.pushState({}, '', url);
参照