Get base URL

Angelos Chalaris · JavaScript, String, Browser, Regexp · Jan 3, 2021

Gets the current URL without any parameters or fragment identifiers.

const getBaseURL = url => url.replace(/[?#].*$/, '');
getBaseURL('http://url.com/page?name=Adam&surname=Smith');
// 'http://url.com/page'

Recommended snippets