Solution 1 :

You could use the URL api.

const url = new URL('');

const output = document.getElementById('output');
output.innerHTML = + url.pathname;
<output id="output"></output>

Problem :

I want to create a button were people can click on to get redirected to a new url based on the current url.


I want everything after collection/ to be removed. What is the easiest way to fix this?


Comment posted by How do I reload the page without the query parameters?

Does this answer your question?

Comment posted by tour

Hi Jip! Welcome to StackOverflow! Please take a look at our

Comment posted by vsync

Why can’t you just