Make Geolosys subpages permalinkable
This commit is contained in:
parent
9d849935f3
commit
ea47cc0348
1 changed files with 34 additions and 22 deletions
|
|
@ -1,12 +1,26 @@
|
||||||
import React, { useState } from 'react';
|
import React, { useState, useEffect } from 'react';
|
||||||
import { CSSTransition } from 'react-transition-group';
|
import { CSSTransition } from 'react-transition-group';
|
||||||
import About from './GeolosysComponents/About';
|
import About from './GeolosysComponents/About';
|
||||||
|
import Datapacks from './GeolosysComponents/Datapacks';
|
||||||
import Config from './GeolosysComponents/Config';
|
import Config from './GeolosysComponents/Config';
|
||||||
import CT from './GeolosysComponents/CraftTweaker';
|
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 () => {
|
export default () => {
|
||||||
const [component, setComponent] = useState('about');
|
const [component, setComponent] = useState(extractComponentName());
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setComponent(extractComponentName());
|
||||||
|
return () => { };
|
||||||
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<CSSTransition classNames="react-router" appear in timeout={300}>
|
<CSSTransition classNames="react-router" appear in timeout={300}>
|
||||||
|
|
@ -37,13 +51,13 @@ export default () => {
|
||||||
</button>
|
</button>
|
||||||
<div className="collapse navbar-collapse" id="navbarSupportedContent">
|
<div className="collapse navbar-collapse" id="navbarSupportedContent">
|
||||||
<ul className="navbar-nav mr-auto mb-2 mb-lg-0">
|
<ul className="navbar-nav mr-auto mb-2 mb-lg-0">
|
||||||
<button
|
<a
|
||||||
className={`nav-link nav-btn ${component === 'about' ? 'active' : ''}`}
|
className={`nav-link ${component === 'about' ? 'active' : ''}`}
|
||||||
type="button"
|
|
||||||
onClick={() => setComponent('about')}
|
onClick={() => setComponent('about')}
|
||||||
|
href="#about"
|
||||||
>
|
>
|
||||||
About
|
About
|
||||||
</button>
|
</a>
|
||||||
<li className="nav-item dropdown">
|
<li className="nav-item dropdown">
|
||||||
<a
|
<a
|
||||||
className={`nav-link dropdown-toggle ${component !== 'about' ? 'active' : ''}`}
|
className={`nav-link dropdown-toggle ${component !== 'about' ? 'active' : ''}`}
|
||||||
|
|
@ -57,33 +71,31 @@ export default () => {
|
||||||
</a>
|
</a>
|
||||||
<ul className="dropdown-menu" aria-labelledby="geolosysDocsDD">
|
<ul className="dropdown-menu" aria-labelledby="geolosysDocsDD">
|
||||||
<li>
|
<li>
|
||||||
<button
|
<a
|
||||||
className={`dropdown-item ${component === 'oreGen' ? 'active' : ''}`}
|
className={`dropdown-item ${component === 'datapacks' ? 'active' : ''}`}
|
||||||
type="button"
|
onClick={() => setComponent('datapacks')}
|
||||||
onClick={() => setComponent('oreGen')}
|
href="#datapacks"
|
||||||
>
|
>
|
||||||
Ore Generation
|
Datapacks
|
||||||
</button>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<button
|
<a
|
||||||
className={`dropdown-item ${component === 'config' ? 'active' : ''}`}
|
className={`dropdown-item ${component === 'config' ? 'active' : ''}`}
|
||||||
type="button"
|
|
||||||
onClick={() => setComponent('config')}
|
onClick={() => setComponent('config')}
|
||||||
|
href="#config"
|
||||||
>
|
>
|
||||||
JSON Config
|
JSON Config
|
||||||
</button>
|
</a>
|
||||||
|
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<button
|
<a
|
||||||
className={`dropdown-item ${component === 'ct' ? 'active' : ''}`}
|
className={`dropdown-item ${component === 'ct' ? 'active' : ''}`}
|
||||||
type="button"
|
|
||||||
onClick={() => setComponent('ct')}
|
onClick={() => setComponent('ct')}
|
||||||
|
href="#ct"
|
||||||
>
|
>
|
||||||
CraftTweaker API
|
CraftTweaker API
|
||||||
</button>
|
</a>
|
||||||
|
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
|
|
@ -94,7 +106,7 @@ export default () => {
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{component === 'about' && (<About />)}
|
{component === 'about' && (<About />)}
|
||||||
{component === 'oreGen' && (<OreGen />)}
|
{component === 'datapacks' && (<Datapacks />)}
|
||||||
{component === 'config' && (<Config />)}
|
{component === 'config' && (<Config />)}
|
||||||
{component === 'ct' && (<CT />)}
|
{component === 'ct' && (<CT />)}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue