21 lines
582 B
TypeScript
21 lines
582 B
TypeScript
import type { Page } from '../../common/types/component.types';
|
|
import type { NavigateFunction } from 'react-router-dom';
|
|
|
|
/**
|
|
* Creates a navigation handler function for event handlers
|
|
* Finds page by ID and navigates to its route
|
|
*/
|
|
export const createNavigateHandler = (
|
|
pages: Page[],
|
|
navigate: NavigateFunction
|
|
): ((pageId: string) => void) => {
|
|
return (pageId: string) => {
|
|
const page = pages.find((p) => p.id === pageId);
|
|
if (page) {
|
|
navigate(page.route);
|
|
} else {
|
|
console.warn(`[Navigation] Page with ID ${pageId} not found`);
|
|
}
|
|
};
|
|
};
|