From ea47cc0348464ff2ab895bfede6a7b0633c5e318 Mon Sep 17 00:00:00 2001 From: oitsjustjose Date: Fri, 4 Jun 2021 20:36:08 -0500 Subject: [PATCH] Make Geolosys subpages permalinkable --- src/components/mods/Geolosys.jsx | 56 +++++++++++++++++++------------- 1 file changed, 34 insertions(+), 22 deletions(-) diff --git a/src/components/mods/Geolosys.jsx b/src/components/mods/Geolosys.jsx index c68b047..6320cbf 100644 --- a/src/components/mods/Geolosys.jsx +++ b/src/components/mods/Geolosys.jsx @@ -1,12 +1,26 @@ -import React, { useState } from 'react'; +import React, { useState, useEffect } from 'react'; import { CSSTransition } from 'react-transition-group'; import About from './GeolosysComponents/About'; +import Datapacks from './GeolosysComponents/Datapacks'; import Config from './GeolosysComponents/Config'; import CT from './GeolosysComponents/CraftTweaker'; -import OreGen from './GeolosysComponents/OreGeneration'; + +const extractComponentName = () => { + const url = window.location.href; + if (url.includes('#')) { + return url.split('#')[1]; + } + + return 'about'; +}; export default () => { - const [component, setComponent] = useState('about'); + const [component, setComponent] = useState(extractComponentName()); + + useEffect(() => { + setComponent(extractComponentName()); + return () => { }; + }, []); return ( @@ -37,13 +51,13 @@ export default () => { {component === 'about' && ()} - {component === 'oreGen' && ()} + {component === 'datapacks' && ()} {component === 'config' && ()} {component === 'ct' && ()}