In my code, I am using JavaScript to replace the current URL. Here is the snippet:
window.location.replace(window.location.href.replace(/\/?$/, '#/view-0'));
However, if the URL looks like this: domain.com/#/test
or domain.com/#/
, it will simply append #/view-0
to the existing hash. My goal is to replace everything after the last part of the URL, including any query strings or hashes.
It seems that my regex is not handling this properly. How can I modify it to be more comprehensive?