首页 > 解决方案 > 从 URL 中删除多个参数之一并在不删除参数的情况下刷新页面但使用其他参数

问题描述

当我使用 javaScript 从 URL 中删除一个参数时,请调用:

window.location.assign(newURL);

没有参数它不会刷新页面。它什么也不做。没有参数如何刷新页面?

编辑:

我有2个参数。它会正确刷新页面并删除所有参数。但是当我在 URL 中保留其中一个参数时,它不会刷新页面。那是我的问题。

网址是:

https://thedomainsample.net/tablet/thePage.html?parameter1=388617¶meter2=true

这是我的代码:

    const queryString = window.location.search;
    const urlParams = new URLSearchParams(queryString);
    const firstParameter = urlParams.get('parameter1');
    
    window.location = window.location.href.split("?")[0]+"?parameter1="+ firstParameter;

它基本上删除了第二个参数并尝试将位置设置为仅使用第一个参数的 URL。它不会刷新页面,它什么也不做。

标签: javascriptrefresh

解决方案


推荐阅读