I have a button that is performing a get to my page and adding a filter to the query string. My code applies that filter to the grid...but the user can remove/edit that fil
I had a similar issue and the way that I approached it was by adding a script in the section. However, in order to avoid inconsistencies when I was moving either backward or forward I needed to add an onbeforeunload event listener. The benefit of that approach is that it avoids the redirection.
// Stores the original url in the local storage window.localStorage.setItem('specifiedKey', window.location.href); // Cleans the query parameter of a string and replace it in the history API const cleanUrl = location.href.match(/^.+(?=\?)/g); window.history.replaceState(null, null, (cleanUrl ? cleanUrl[0] : location.href)); // the history is updated before the window reloads window.onbeforeunload = () => { window.history.replaceState(null, null, window.localStorage.getItem('specifiedKey')); }
The only issue that I imagine is browser incompatibility, with the JavaScript engine not being able to support a regex look-behind operator. This can be easily fixed using .split('?')[0]
Don't use a module for doing something like that:
res.redirect( req.originalUrl.split("?").shift() );
// load built-in utilities for URL resolution and parsing
var url = require('url');
function removeQueryString(url){
// split url into distinct parts
// (full list: https://nodejs.org/api/url.html#url_url_parse_urlstr_parsequerystring_slashesdenotehost)
var obj = url.parse(url);
// remove the querystring
obj.search = obj.query = "";
// reassemble the url
return url.format(obj);
}