mirror of
https://github.com/kou029w/_.git
synced 2025-01-31 06:18:07 +00:00
fix tabs
This commit is contained in:
parent
bb0f17646f
commit
e95f7506a5
1 changed files with 22 additions and 13 deletions
|
@ -6,33 +6,42 @@ import Tabs from "@material-ui/core/Tabs";
|
||||||
import Tab from "@material-ui/core/Tab";
|
import Tab from "@material-ui/core/Tab";
|
||||||
import routes from "../routes";
|
import routes from "../routes";
|
||||||
|
|
||||||
|
const basePath = process.env.NEXT_PUBLIC_BASE_PATH ?? "";
|
||||||
|
|
||||||
const TopAppBar = () => {
|
const TopAppBar = () => {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const pathname = (
|
const currentPathname = React.useMemo(
|
||||||
routes.find(({ pathname }) => pathname === router.pathname) || {
|
() =>
|
||||||
pathname: "/",
|
router.pathname.startsWith(basePath)
|
||||||
}
|
? router.pathname.slice(basePath.length)
|
||||||
).pathname;
|
: router.pathname,
|
||||||
|
[router.pathname]
|
||||||
|
);
|
||||||
|
const tabPathname = React.useMemo(
|
||||||
|
() =>
|
||||||
|
routes.reduce(
|
||||||
|
(prev, { pathname }) =>
|
||||||
|
pathname === currentPathname ? pathname : prev,
|
||||||
|
"/"
|
||||||
|
),
|
||||||
|
[currentPathname]
|
||||||
|
);
|
||||||
return (
|
return (
|
||||||
<AppBar color="default">
|
<AppBar color="default">
|
||||||
<Tabs
|
<Tabs
|
||||||
value={pathname}
|
value={tabPathname}
|
||||||
variant="fullWidth"
|
variant="fullWidth"
|
||||||
indicatorColor="primary"
|
indicatorColor="primary"
|
||||||
textColor="primary"
|
textColor="primary"
|
||||||
>
|
>
|
||||||
{routes.map(({ pathname, icon }) => (
|
{routes.map(({ pathname, icon }, index) => (
|
||||||
<Tab
|
<Tab
|
||||||
key={pathname}
|
key={index}
|
||||||
value={pathname}
|
value={pathname}
|
||||||
icon={icon}
|
icon={icon}
|
||||||
component={React.forwardRef<HTMLAnchorElement, {}>((props, ref) => (
|
component={React.forwardRef<HTMLAnchorElement, {}>((props, ref) => (
|
||||||
<Link href={pathname}>
|
<Link href={pathname}>
|
||||||
<a
|
<a ref={ref} href={[basePath, pathname].join("")} {...props} />
|
||||||
ref={ref}
|
|
||||||
href={[process.env.NEXT_PUBLIC_BASE_PATH, pathname].join("")}
|
|
||||||
{...props}
|
|
||||||
/>
|
|
||||||
</Link>
|
</Link>
|
||||||
))}
|
))}
|
||||||
/>
|
/>
|
||||||
|
|
Loading…
Add table
Reference in a new issue