From 015b7dc5298c9bd9108568052f85b90c25743ddd Mon Sep 17 00:00:00 2001 From: Mathias Wagner Date: Wed, 31 May 2023 01:57:45 +0200 Subject: [PATCH] Added a dynamic title to the Content.jsx --- .../src/common/components/Content/Content.jsx | 30 ++++++++++++------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/client/src/common/components/Content/Content.jsx b/client/src/common/components/Content/Content.jsx index a5bbe0d..d461085 100644 --- a/client/src/common/components/Content/Content.jsx +++ b/client/src/common/components/Content/Content.jsx @@ -1,13 +1,21 @@ import "./styles.sass"; -import {routes} from "@/common/routes"; -import {Route, Routes} from "react-router-dom"; +import {getByPath, routes} from "@/common/routes"; +import {Route, Routes, useLocation} from "react-router-dom"; +import {useEffect} from "react"; -export const Content = () => ( -
- - {Object.keys(routes).map((route) => (routes[route].map((route) => ( - - ))))} - -
-) \ No newline at end of file +export const Content = () => { + const location = useLocation(); + + useEffect(() => { + document.title = "PowerTools - " + (getByPath(location.pathname)?.name || "404"); + }, [location]); + + return ( +
+ + {Object.keys(routes).map((route) => (routes[route].map((route) => ( + + ))))} + +
); +} \ No newline at end of file