From 5f5d23f4ded2e7755598535c8264882ae103d161 Mon Sep 17 00:00:00 2001 From: He4eT Date: Fri, 19 Feb 2021 00:53:39 +0500 Subject: [PATCH] Bootstrap app --- index.html | 7 +++++-- src/index.js | 40 ++++++++++++++++++++++++++++++++++++++ src/utils/utils.routing.js | 21 ++++++++++++++++++++ 3 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 src/index.js create mode 100644 src/utils/utils.routing.js 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] +}