Added removeParameter function that can remove a query parameter from the route.
This commit is contained in:
		@@ -472,6 +472,24 @@ class Router {
 | 
			
		||||
            return (params.has(name) ? params.get(name) : null);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Removes a query parameter from the route search if it exists.
 | 
			
		||||
     * @param {String} name 
 | 
			
		||||
     */
 | 
			
		||||
    static removeParameter(name) {
 | 
			
		||||
        if (Router.hashMode) {
 | 
			
		||||
            var params = new URLSearchParams(window.location.hash.includes("?") ? "?" + window.location.hash.split("?")[1] : "");
 | 
			
		||||
            if (params.has(name)) {
 | 
			
		||||
                params.delete(name);
 | 
			
		||||
                window.location.hash = window.location.hash.split("?")[0] + "?" + params.toString();
 | 
			
		||||
            }
 | 
			
		||||
        } else {
 | 
			
		||||
            var url = new URL(window.location);
 | 
			
		||||
            url.searchParams.delete(name);
 | 
			
		||||
            window.history.pushState(null, '', url.toString());
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Router.states = [];
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user