-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
33 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { isBrowser } from '../utils' | ||
import { useRouter } from '../useApi' | ||
import { computed } from 'vue' | ||
import { HistoryState } from './common' | ||
|
||
/** | ||
* Reactive history state. Only available in browser. | ||
* | ||
* @experimental - DO NOT use in production | ||
*/ | ||
export function useHistoryState<T = HistoryState>() { | ||
const router = useRouter() | ||
return computed<Readonly<T>>(() => { | ||
if (!isBrowser) { | ||
return {} | ||
} | ||
|
||
// Enforce automatically update when navigation happens | ||
router.currentRoute.value | ||
return window.history.state | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters