@jay-js/system
Version:
A powerful and flexible TypeScript library for UI, state management, lazy loading, routing and managing draggable elements in modern web applications.
40 lines (39 loc) • 1.55 kB
TypeScript
type BeforeNavigateFunction = () => boolean | Promise<boolean>;
/**
* Register a function to be executed before the next navigation.
* The navigation will only proceed if the function returns true.
* The function is automatically removed after being executed once.
*
* @param {Function} guardFn - Function that returns boolean or Promise<boolean>
* @param {Object} options - Additional options (reserved for future use)
* @returns {Function} - Function to manually remove the guard if needed
*
* @example
* // Prevent navigation if form has unsaved changes
* beforeNavigate(() => {
* if (formHasUnsavedChanges()) {
* return confirm('You have unsaved changes. Are you sure you want to leave?');
* }
* return true;
* });
*/
export declare function beforeNavigate(guardFn: BeforeNavigateFunction): () => void;
/**
* Navigates to a specified path programmatically
*
* This function updates the browser URL and triggers route resolution without requiring a full page reload.
* If a prefix is configured in the router options, it will be automatically applied to the path.
*
* Before navigation occurs, any registered beforeNavigate guards are executed.
* The navigation will only proceed if all guards return true.
*
* @param {string} path - The target path to navigate to (without the prefix)
*
* @example
* // Navigate to the about page
* navigate('/about');
*
* // With a configured prefix of '/app', this would navigate to '/app/about'
*/
export declare function navigate(path: string): Promise<void>;
export {};