Spaces:
Configuration error
Configuration error
File size: 1,026 Bytes
7bbd534 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
import { IRoute } from '@/types/navigation';
// NextJS Requirement
export const isWindowAvailable = () => typeof window !== 'undefined';
export const findCurrentRoute = (
routes: IRoute[],
pathname: string,
): IRoute | undefined => {
for (let route of routes) {
if (route.items) {
const found = findCurrentRoute(route.items, pathname);
if (found) return found;
}
if (pathname?.match(route.path) && route) {
return route;
}
}
};
export const getActiveRoute = (routes: IRoute[], pathname: string): string => {
const route = findCurrentRoute(routes, pathname);
return route?.name || 'Default Brand Text';
};
export const getActiveNavbar = (
routes: IRoute[],
pathname: string,
): boolean => {
const route = findCurrentRoute(routes, pathname);
if (route?.secondary) return route?.secondary;
else return false;
};
export const getActiveNavbarText = (
routes: IRoute[],
pathname: string,
): string | boolean => {
return getActiveRoute(routes, pathname) || false;
};
|