删除网址参数 JS ES6



我有一个包含参数的网址,我想删除它。我已经创建了一个if...else条件,但我想在 ES6 中改进它。

if ( window.location.search.indexOf('&submit')  > -1 ) {
    window.location = urlBase + '/' + window.location.search;
} else {
    window.location = urlBase + '/' + window.location.search + '&submit=1';
}

提前谢谢你。

不确定您的目标是什么,但在这里我只是使用了includes和模板文字。

if (window.location.search.includes('&submit')) {
    window.location = `${urlBase}/${window.location.search}`;
} else {
    window.location = `${urlBase}/${window.location.search}&submit=1`;
}

最新更新