You should remove delete
parameter from URL after page loaded. You can do it with js:
window.history.replaceState({}, '', location.href.replace(location.search, ""));
How it works
- this method modifies the current URL without putting this into history
window.history.replaceState
- First parameter:
{}
The state object is a JavaScript object which is associated with the history entry passed to the replaceState method. The state object can be null.
- Second parameter:
''
This parameter exists for historical reasons, and cannot be omitted; passing the empty string is traditional, and safe against future changes to the method.
- Third parameter (new URL):
first part (
location.href
) is complete URL value, like:
http://example.com/page.php?delete=10
then it will replace search parameters with empty string:
.replace(location.search, "")
location.search
is everything after ? in URL (in this case: ?delete=10
)
History.replaceState()
Edit
If you have multiple parameters in your URL and you want to remove only delete parameter try this code:
// Create new URLSearchParams object
// location.search is something like "?delete=10&msg=hello&ok=true"
let params = new URLSearchParams(location.search);
// Remove delete parameter from URL parameters
params.delete("delete");
// Convert parameters to string
// e.g "msg=hello&ok=true"
let urlParams = params.toString();
// if urlParams is not empty add a question mark before it:
urlParams = urlParams.length > 0 ? "?" + urlParams : "";
// Replace new parameters
window.history.replaceState({}, '', urlParams);