Skip to main content

location

Read and manipulate the browser's window.location โ€” current URL, pathname, query string, hash, redirects, and reloads.

Import: @rtorcato/browser-common/location

๐Ÿ“– MDN: Location

Browser supportโ€‹

APIChromeEdgeFirefoxSafariiOS SafariBaseline
Locationโœ… 1+โœ… 12+โœ… 1+โœ… 1+โœ… 1+Widely available

โœ… supported ยท โ— partial ยท โŒ not supported ยท [n] see note. Generated from MDN browser-compat-data and web-features. caniuse: Location

Exampleโ€‹

import { getCurrentLocation, getPathname, redirectTo } from '@rtorcato/browser-common/location'

const url = getCurrentLocation()

if (getPathname() === '/login') {
redirectTo('/dashboard')
}

Exportsโ€‹

  • getCurrentLocation() โ€” current URL (window.location.href), or undefined outside a browser
  • redirectTo(url) โ€” navigates to a new URL
  • reloadPage() โ€” reloads the current page
  • getPathname() โ€” current pathname, or undefined outside a browser
  • getSearch() โ€” current query string, or undefined outside a browser
  • getHash() โ€” current hash, or undefined outside a browser

See the API reference for full signatures.