Able Pro is already rendering the menu from the backend. The dashboard menus (Default, Analytics) are rendered via the back end.
export const endpoints = {
key: 'api/menu',
dashboard: '/dashboard' // server URL
};
export function useGetMenu() {
const { data, isLoading, error, isValidating } = useSWR(endpoints.key + endpoints.dashboard, fetcher, {
revalidateIfStale: false,
revalidateOnFocus: false,
revalidateOnReconnect: false
});
const memoizedValue = useMemo(
() => ({
menu: data?.dashboard as NavItemType,
menuLoading: isLoading,
menuError: error,
menuValidating: isValidating,
menuEmpty: !isLoading && !data?.length
}),
[data, error, isLoading, isValidating]
);
return memoizedValue;
}
src/layout/Dashboard/Drawer/DrawerContent/Navigation/index.tsx
import { useGetMenu } from 'api/menu';
// ==============================|| DRAWER CONTENT - NAVIGATION ||============================== //
export default function Navigation() {
const { menuLoading } = useGetMenu();
useLayoutEffect(() => {
if (menuLoading && !isFound(menuItem, 'group-dashboard-loading')) {
menuItem.items.splice(0, 0, dashboardMenu);
setMenuItems({ items: [...menuItem.items] });
} else if (!menuLoading && dashboardMenu?.id !== undefined && !isFound(menuItem, 'group-dashboard')) {
menuItem.items.splice(0, 1, dashboardMenu);
setMenuItems({ items: [...menuItem.items] });
} else {
setMenuItems({ items: [...menuItem.items] });
}
// eslint-disable-next-line
}, [menuLoading]);
...
}