import { NextRouter, useRouter } from 'next/router' import Link from 'next/link' export function TopBarNavLink({ labelText, to, match, }: { labelText: string to: string match?: string | { startsWith: string } }) { const router = useRouter() const isInternal = to[0] === '/' || to[0] === '#' const LinkComponent = isInternal ? Link : 'a' const isRouteMatched = checkIsRouteMatched(router, match) return ( ) } const LinkContent = ({ labelText }: { labelText: string }) => { return (
{labelText}
) } export const checkIsRouteMatched = ( router: NextRouter, match?: string | { startsWith: string } ) => { if (!match) return false if (router.asPath === '/') { return match === '/' } else if (typeof match === 'string') { return ( router.asPath === match || router.asPath === '/' || router.asPath.startsWith(match + '?') ) } else if (match.startsWith && typeof match.startsWith === 'string') { return router.asPath.startsWith(match.startsWith) } return false }