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.

67 lines 3 kB
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; import { routerOptions } from "../configuration"; import { getPotentialMatch, getPotentialMatchIndex } from "../matching/get-potential-match"; import { renderRoute } from "../rendering/render-route"; export function getRoute() { return __awaiter(this, void 0, void 0, function* () { const pathName = routerOptions.setPathname ? routerOptions.setPathname() : window.location.pathname; const match = getPotentialMatch(pathName); if (routerOptions.beforeResolve) { const beforeResolve = yield routerOptions.beforeResolve(match.route); if (!beforeResolve) { return; } } if (!match.result) { if (routerOptions.onError) { routerOptions.onError(new Error("No match found", { cause: "no-match" })); return; } return; } // Check route guard if present if (match.route.guard) { try { const guardResult = yield match.route.guard(match.route); if (!guardResult) { // Guard rejected the navigation if (routerOptions.onError) { routerOptions.onError(new Error("Route access denied by guard", { cause: "guard-rejected" })); } return; } } catch (error) { // Guard threw an error if (routerOptions.onError) { routerOptions.onError(error instanceof Error ? error : new Error("Route guard error", { cause: error })); } return; } } if (match.route.layout) { const matchLayoutIndex = getPotentialMatchIndex(pathName); if (!matchLayoutIndex.route) { if (routerOptions.onError) { routerOptions.onError(new Error("No layout match found", { cause: "no-layout-match" })); return; } return; } yield renderRoute(matchLayoutIndex.route); return; } yield renderRoute(match.route); return; }); } window.addEventListener("popstate", () => getRoute()); //# sourceMappingURL=get-route.js.map