front: use ReactRouting to manage Component's contetnt
This commit is contained in:
parent
6c46e8fb98
commit
9f4bb9454e
@ -6,7 +6,6 @@ import Header from "./components/Header"
|
||||
import Leaderboard from "./components/Leaderboard"
|
||||
import Game from "./components/Game"
|
||||
import About from "./components/About"
|
||||
import GameProposal from './components/Game/Proposal'
|
||||
|
||||
function App() {
|
||||
|
||||
@ -15,10 +14,13 @@ function App() {
|
||||
<Header/>
|
||||
<div className="Container">
|
||||
<Routes>
|
||||
<Route path="/leaderboard" element={<Leaderboard/>} />
|
||||
<Route path="/game" element={<Game/>} />
|
||||
<Route path="/game/proposal" element={<Game/>} />
|
||||
<Route path="/game/active" element={<Game/>} />
|
||||
<Route path="/game/archive" element={<Game/>} />
|
||||
|
||||
<Route path="/leaderboard" element={<Leaderboard/>} />
|
||||
<Route path="/about" element={<About/>} />
|
||||
<Route path="/game/proposal" element={<GameProposal/>} />
|
||||
</Routes>
|
||||
</div>
|
||||
</BrowserRouter>
|
||||
|
@ -1,11 +1,19 @@
|
||||
import './index.css';
|
||||
import React from 'react';
|
||||
import { useLocation, matchPath } from "react-router";
|
||||
|
||||
import { AppData } from "../../context/data"
|
||||
|
||||
export default function Game() {
|
||||
const [data] = React.useContext(AppData)
|
||||
|
||||
const { pathname } = useLocation();
|
||||
const isProposalPath = matchPath("/game/proposal/*", pathname);
|
||||
const isActivelPath = matchPath("/game/active/*", pathname);
|
||||
const isArchivePath = matchPath("/game/archive/*", pathname);
|
||||
|
||||
console.log("path: Proposal ", isProposalPath != null, "Active", isActivelPath != null, "Archive", isArchivePath != null )
|
||||
|
||||
if (!data?.games)
|
||||
return <div>Loading..</div>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user