location url will also contain query string. Does pathname property only gives the url without query string ? if not, then you have to write logic removing the query string if it's available.