@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.
30 lines (29 loc) • 839 B
JavaScript
import { getPotentialMatches } from "./getPotentialMatches.js";
import { resolvedRoutes } from "./routerDefineOptions.js";
export function getPotentialMatch() {
const potentialMatches = getPotentialMatches();
const firstRoute = resolvedRoutes.values().next().value;
const resultMatch = potentialMatches.reduce((acc, curr)=>{
if (curr.result !== null) {
if (acc.result === null) {
return curr;
}
// TODO (Fix Routing System <-)
/* if (curr.result.length > acc.result.length) {
return curr;
} */ }
return acc;
}, {
route: firstRoute,
result: null
});
if (resultMatch) {
return resultMatch;
}
return {
route: firstRoute,
result: [
location.pathname
]
};
}