UNPKG

@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.

45 lines 1.36 kB
/** * Default configuration options for the router * @type {TRouterOptions} */ export const routerOptions = { prefix: "", target: document.body, onError: console.error, beforeResolve: () => true, }; /** * Map of resolved routes indexed by their unique IDs * @type {Map<string, TRouteInstance>} */ export const resolvedRoutes = new Map(); /** * Configures the router with the specified options * * This function allows customizing router behavior by providing configuration options. * It handles special cases like resolving string targets to DOM elements. * * @param {Partial<TRouterOptions>} options - Partial router configuration options * @returns {void} * * @example * routerDefineOptions({ * prefix: '/app', * target: '#content', * onError: (err) => showErrorToast(err.message) * }); */ export function routerDefineOptions(options) { if (typeof options.target === "string") { const targetElement = document.querySelector(options.target); if (!targetElement) { if (options.onError) { options.onError(new Error(`Target element not found: ${options.target}`, { cause: "invalid-target" })); } return; } options.target = targetElement; } Object.assign(routerOptions, options); } //# sourceMappingURL=configuration.js.map