Remove querystring parameters from url with regex

A regular expression is probably more than you need.

You could do the following to remove the ? and everything (query string + hash) after it:

var routeData = route.split("?")[0];

If you truly wanted to strip only the query string, you could preserve the hash by reconstructing the URL from the window.location object:

var routeData = window.location.origin + window.location.pathname + window.location.hash;

If you want the query string, you can read it with window.location.search.


i just used this one

    var routeData= route.substring(0, route.indexOf('?'));