Skip to content

useBrowserLocation

Category
Export Size
650 B
Last Changed
5 days ago

Reactive browser location

Demo

Usage

tsx
import { 
useBrowserLocation
} from '@reause/core'
const
location
=
useBrowserLocation
()
// read the current URL parts const {
href
,
pathname
,
search
,
hash
} =
location
console
.
log
(
href
) // 'https://example.com/path?q=1#anchor'
// navigate by assigning a writable field
location
.
hash
= '#top'

NOTE: If you're using React Router, use the location utilities provided by the router instead.

Type Declarations

ts
export interface UseBrowserLocationOptions extends ConfigurableWindow {
}

export interface BrowserLocationState {
    readonly trigger: string;
    readonly state?: any;
    readonly length?: number;
    readonly origin?: string;
    hash?: string;
    host?: string;
    hostname?: string;
    href?: string;
    pathname?: string;
    port?: string;
    protocol?: string;
    search?: string;
}

export function useBrowserLocation(options?: UseBrowserLocationOptions): BrowserLocationState

Source

Source · Demo · VueUse

Contributors

hairyf

Changelog

v0.1.0 on
08cba - fix(core): resolve useBrowserLocation audit findings (#529)
8855a - feat(core): add useBrowserLocation (#87)

Released under the MIT License. v0.1.8