up.history up.history.isLocation(url, [options])
JavaScript function

Returns whether the given URL matches the current browser location.

Examples

location.pathname // => '/path'

up.history.isLocation('/path') // result: true
up.history.isLocation('/other') // result: false

By default, a trailing #hash and a ?query string are considered for the comparison. To ignore the #hash, pass { hash: false }:

location.pathname // => '/path'

up.history.isLocation('/path#hash') // result: false
up.history.isLocation('/path#hash', { hash: false }) // result: true
up.history.isLocation('/path?query') // result: false

The given URL is normalized, so any URL string pointing to the browser location will match:

location.hostname // result: 'current-host'
location.pathname // => '/foo'

up.history.isLocation('/foo') // result: true
up.history.isLocation('http://current-host/foo') // result: true
up.history.isLocation('http://other-host/foo') // result: false

Parameters

url
required

The URL to compare against the current browser location.

This can be either an absolute pathname (/path), a relative filename (index.html), or a fully qualified URL (https://...).

Type: string
[options.hash=true]
optional

Whether to consider #hash fragments in the given or current URLs.

When set to false, this function will consider the URLs /foo#one and /foo#two to be equal.

Type: boolean

Return value

Whether the browser is currently at the given location.

Type: boolean