mirror of
https://github.com/luxfi/explore.git
synced 2026-09-24 00:28:18 +00:00
21 lines
533 B
TypeScript
21 lines
533 B
TypeScript
import { useRouter } from 'next/router';
|
|
import React from 'react';
|
|
|
|
import type { RouteName } from 'lib/link/routes';
|
|
import { ROUTES } from 'lib/link/routes';
|
|
|
|
export default function useCurrentRoute() {
|
|
const { route: nextRoute } = useRouter();
|
|
|
|
return React.useCallback((): RouteName => {
|
|
for (const routeName in ROUTES) {
|
|
const route = ROUTES[routeName as RouteName];
|
|
if (route.pattern === nextRoute) {
|
|
return routeName as RouteName;
|
|
}
|
|
}
|
|
|
|
return 'network_index';
|
|
}, [ nextRoute ]);
|
|
}
|