@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.
25 lines (24 loc) • 822 B
JavaScript
import { Routes } from "./Routes.js";
import { getRoute } from "./getRoute.js";
import { resolvedRoutes, routerDefineOptions } from "./routerDefineOptions.js";
export function Router(routes, options) {
if (options) {
routerDefineOptions(options);
}
if (routes.length === 0) {
if (options === null || options === void 0 ? void 0 : options.onError) {
options.onError(new Error("No routes provided", {
cause: "no-routes"
}));
return;
}
throw new Error("No routes provided", {
cause: "no-routes"
});
}
resolvedRoutes.clear();
for (const route of Routes(routes, options === null || options === void 0 ? void 0 : options.target)){
resolvedRoutes.set(route.id, route);
}
getRoute();
}