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โ
| API | Chrome | Edge | Firefox | Safari | iOS Safari | Baseline |
|---|---|---|---|---|---|---|
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), orundefinedoutside a browserredirectTo(url)โ navigates to a new URLreloadPage()โ reloads the current pagegetPathname()โ current pathname, orundefinedoutside a browsergetSearch()โ current query string, orundefinedoutside a browsergetHash()โ current hash, orundefinedoutside a browser
See the API reference for full signatures.