Function getBaseURL

  • Get the base URL without any query parameters or hash fragments.
    If the input is not a string or is an empty string, an empty string will be returned.

    Since

    vx.x.x

    Returns

    The base URL without any query parameters or hash fragments.

    Example

    // Get base URL
    const url = 'https://www.example.com/path/to/page'
    console.log(
    getBaseURL(url)
    )
    => https://www.example.com/path/to/page

    Example

    // Get base URL with query parameters
    const url = 'https://www.example.com/path/to/page?param1=value1&param2=value2'
    console.log(
    getBaseURL(url)
    )
    => https://www.example.com/path/to/page

    Parameters

    • url: string

      The URL to get the base URL from.

    Returns string