Not sure if this is inapropriate albeit it working fine.
In order to move to a new location and retain the root URL, I do examples like this :
window.location = window.location.href.split('/oldbar')[0] + '/foobar/' + $value
window.location = window.location.href.split(/oldbar/)[0] + 'foobar';
window.location = window.location.href.split('/oldbar')[0] + '/foobar/'
Would you do it differently? If so how / why?
You don’t need to split up the href when you can just access the
pathnameproperty of the location object: