Shouldn't be ``url.replace(/#.*$/, '');`` to remove all the fragment ?