From ae4c17b39133a259141eacc623f71b678ea47750 Mon Sep 17 00:00:00 2001 From: ValdiANS Date: Thu, 4 Dec 2025 22:45:57 +0700 Subject: [PATCH] chore: create isPathActive helper --- src/lib/helper.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/lib/helper.ts b/src/lib/helper.ts index 2c66e1cf..13fdce5d 100644 --- a/src/lib/helper.ts +++ b/src/lib/helper.ts @@ -119,3 +119,16 @@ export const convertRowSelectionObjToArr = ( return result; }; + +export const isPathActive = (pathname: string, link?: string) => { + if (!link) return false; + + const splittedPathname = pathname.split('/'); + const splittedLink = link.split('/'); + + const isActiveLinkValid = splittedLink.every((linkChunk, idx) => { + return linkChunk === splittedPathname[idx]; + }); + + return pathname.startsWith(link) && isActiveLinkValid; +};