Skip to content

Commit fc49aca

Browse files
committed
refactor: menu에 includes추가로 / 경로도 header에 Blog active
1 parent b3a155d commit fc49aca

4 files changed

Lines changed: 18 additions & 6 deletions

File tree

src/components/HeaderLink.astro

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
---
22
import type { HTMLAttributes } from 'astro/types';
33
4-
type Props = HTMLAttributes<'a'>;
4+
type Props = HTMLAttributes<'a'> & {
5+
incldues: string[];
6+
};
57
6-
const { href, class: className, ...props } = Astro.props;
8+
const { href, incldues, class: className, ...props } = Astro.props;
79
810
const { pathname } = Astro.url;
911
const subpath = pathname.match(/[^\/]+/g);
10-
const isActive = href === pathname || href === '/' + subpath?.[0];
12+
const isActive = incldues.find((path) => {
13+
return path === pathname || path === '/' + subpath?.[0];
14+
});
1115
---
1216

1317
<a

src/components/Navigation.astro

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ import { menu } from '@/constants/menu';
77
{
88
menu.map((item) => (
99
<li>
10-
<HeaderLink href={item.path}>{item.label}</HeaderLink>
10+
<HeaderLink href={item.path} incldues={item.includes}>
11+
{item.label}
12+
</HeaderLink>
1113
</li>
1214
))
1315
}

src/components/NavigationMobile.astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import HamburgerSvg from './HamburgerSvg.astro';
1212
{
1313
menu.map((item) => (
1414
<li>
15-
<HeaderLink href={item.path} class="block">
15+
<HeaderLink href={item.path} incldues={item.includes} class="block">
1616
{item.label}
1717
</HeaderLink>
1818
</li>

src/constants/menu.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
1-
export const menu = [
1+
export const menu: {
2+
path: string;
3+
label: string;
4+
includes: string[];
5+
}[] = [
26
{
37
path: '/blog',
48
label: 'Blog',
9+
includes: ['/', '/blog'],
510
},
611
{
712
path: '/about',
813
label: 'About',
14+
includes: ['/about'],
915
},
1016
];

0 commit comments

Comments
 (0)