mirror of
https://github.com/He4eT/elseifplayer.git
synced 2026-05-05 01:17:22 +00:00
Bootstrap app
This commit is contained in:
parent
66690ed4e0
commit
5f5d23f4de
3 changed files with 66 additions and 2 deletions
21
src/utils/utils.routing.js
Normal file
21
src/utils/utils.routing.js
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
import {
|
||||
useState, useEffect, useCallback
|
||||
} from 'preact/hooks'
|
||||
|
||||
export const useHashLocation = () => {
|
||||
const currentLoc = () =>
|
||||
window.location.hash.replace('#', '') || '/'
|
||||
|
||||
const [loc, setLoc] = useState(currentLoc())
|
||||
|
||||
useEffect(() => {
|
||||
const handler = () => setLoc(currentLoc())
|
||||
|
||||
window.addEventListener('hashchange', handler)
|
||||
return () => window.removeEventListener('hashchange', handler)
|
||||
}, [])
|
||||
|
||||
const navigate = useCallback(to =>
|
||||
(window.location.hash = to.replace('#/', '')), [])
|
||||
return [loc, navigate]
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue