diff --git a/index.html b/index.html index e22c323..bcf7d14 100644 --- a/index.html +++ b/index.html @@ -2,10 +2,13 @@ - + IFPlayer - +
+ diff --git a/src/index.js b/src/index.js new file mode 100644 index 0000000..e699b53 --- /dev/null +++ b/src/index.js @@ -0,0 +1,40 @@ +import { h, render } from 'preact' +import { + Redirect, Switch, Route, Link, Router +} from 'wouter-preact' + +import { useHashLocation } from '/src/utils/utils.routing' + +function App () { + return ( + +
+ + +
+ + + Root + + + About + + + + + + 404 + + +
+
+
+ ) +} + +render(, document.getElementById('root')) diff --git a/src/utils/utils.routing.js b/src/utils/utils.routing.js new file mode 100644 index 0000000..48a255d --- /dev/null +++ b/src/utils/utils.routing.js @@ -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] +}