1
0
Fork 0
mirror of https://github.com/kou029w/_.git synced 2025-01-30 22:08:02 +00:00
This commit is contained in:
Nebel 2020-06-11 23:19:57 +09:00
parent bb0f17646f
commit e95f7506a5

View file

@ -6,33 +6,42 @@ import Tabs from "@material-ui/core/Tabs";
import Tab from "@material-ui/core/Tab";
import routes from "../routes";
const basePath = process.env.NEXT_PUBLIC_BASE_PATH ?? "";
const TopAppBar = () => {
const router = useRouter();
const pathname = (
routes.find(({ pathname }) => pathname === router.pathname) || {
pathname: "/",
}
).pathname;
const currentPathname = React.useMemo(
() =>
router.pathname.startsWith(basePath)
? router.pathname.slice(basePath.length)
: router.pathname,
[router.pathname]
);
const tabPathname = React.useMemo(
() =>
routes.reduce(
(prev, { pathname }) =>
pathname === currentPathname ? pathname : prev,
"/"
),
[currentPathname]
);
return (
<AppBar color="default">
<Tabs
value={pathname}
value={tabPathname}
variant="fullWidth"
indicatorColor="primary"
textColor="primary"
>
{routes.map(({ pathname, icon }) => (
{routes.map(({ pathname, icon }, index) => (
<Tab
key={pathname}
key={index}
value={pathname}
icon={icon}
component={React.forwardRef<HTMLAnchorElement, {}>((props, ref) => (
<Link href={pathname}>
<a
ref={ref}
href={[process.env.NEXT_PUBLIC_BASE_PATH, pathname].join("")}
{...props}
/>
<a ref={ref} href={[basePath, pathname].join("")} {...props} />
</Link>
))}
/>