Skip to content

Commit

Permalink
Refactor TabItem component to extract base path logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Kota8102 committed Nov 15, 2024
1 parent 3fb3181 commit 3b9be58
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/frontend/src/components/ui/Tab/TabItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@ export const TabItem = ({ path, label: text, activeIcon, inactiveIcon }: TabConf
// 現在のパス情報を取得
const { pathname } = useLocation()

// パスからベースパスを抽出する関数
const extractBasePath = (url: string) => {
return `/${url.split('/').slice(1, 3).join('/')}`
}

// 現在のパスとリンク先パスから、ベースパスを抽出
// 例: /app/flower/2023-12-25 -> /app/flower
const basePath = `/${pathname.split('/').slice(1, 3).join('/')}`
const linkBasePath = `/${path.split('/').slice(1, 3).join('/')}`
const basePath = extractBasePath(pathname)
const linkBasePath = extractBasePath(path)

// 現在のタブがアクティブかどうかを判定
const isActive = basePath === linkBasePath
Expand Down

0 comments on commit 3b9be58

Please sign in to comment.