getBaseURL

JavaScript, String, Browser, Regexp

Gets the current URL without any parameters or fragment identifiers.

  • Use String.prototype.replace() with an appropriate regular expression to remove everything after either '?' or '#', if found.
const getBaseURL = url => url.replace(/[?#].*$/, '');
getBaseURL('http://url.com/page?name=Adam&surname=Smith');
// 'http://url.com/page'

Recommended snippets

  • getURLParameters

    JavaScript, Browser

    Creates an object containing the parameters of the current URL.

  • URLJoin

    JavaScript, String

    Joins all given URL segments together, then normalizes the resulting URL.

  • isAbsoluteURL

    JavaScript, String

    Checks if the given string is an absolute URL.