Skip to content

useUrlState ​

A hook that store the state into url query.

Install ​

bash
npm i @vue-hooks-plus/use-url-state

Code demonstration ​

API ​

typescript
const state = useUrlState(defaultState, {
  localStorageKey: 'localStorageKey',
  routerPushFn,
})

interface UseUrlStateOptions {
  localStorageKey?: string
}

Params ​

PropertyDescriptionTypeDefault
initialStatedefaultS | () => S-
optionsWhen setting localStorageKey, if url has no parameter, the value of localStorage is used
UseUrlStateOptions-routerPushFn

Result ​

PropertyDescriptionType
stateUrl query object-

Source ​

Source · Document · Demo

Released under the MIT License.