diff --git a/styles/TopAppBar.tsx b/styles/TopAppBar.tsx index 714b171..af27065 100644 --- a/styles/TopAppBar.tsx +++ b/styles/TopAppBar.tsx @@ -1,36 +1,31 @@ -import React, { useState } from "react"; -import { withRouter } from "next/router"; +import React from "react"; +import { useRouter } from "next/router"; import { AppBar, Tabs, Tab } from "@material-ui/core"; import routes from "../routes"; -const TopAppBar = withRouter(({ router }) => { - const [value, setValue] = useState( - routes.findIndex(({ pathname }) => pathname === router.pathname) - ); - router.events.on("routeChangeStart", (url: string) => { - setValue( - routes.findIndex( - ({ pathname }) => pathname === url.replace(/(?<=.)\/$/, "") - ) - ); - }); +const TopAppBar = () => { + const router = useRouter(); + const pathname = ( + routes.find(({ pathname }) => pathname === router.pathname) || { + pathname: "/" + } + ).pathname; return ( { - router.push(routes[value].pathname); - setValue(value); + router.push(value); }} variant="fullWidth" indicatorColor="primary" textColor="primary" > - {routes.map(({ icon }, i) => ( - + {routes.map(({ pathname, icon }) => ( + ))} ); -}); +}; export default TopAppBar;