From 0a8685360f456273a004a481f5cb0b075928b983 Mon Sep 17 00:00:00 2001 From: Jorik Schellekens Date: Wed, 16 Sep 2020 13:04:18 +0100 Subject: [PATCH] Update app on hashchange --- src/App.tsx | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index c9205ba..46e5698 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -import React from 'react'; +import React, { useState, useEffect } from 'react'; import SingleColumn from './layouts/SingleColumn'; import CreateLinkTile from './components/CreateLinkTile'; @@ -36,9 +36,13 @@ const App: React.FC = () => { ); - if (location.hash) { - if (location.hash.startsWith('#/')) { - page = ; + const [hash, setHash] = useState(location.hash); + + useEffect(() => (window.onhashchange = () => setHash(location.hash)), []); + + if (hash) { + if (hash.startsWith('#/')) { + page = ; } else { page = (