UNPKG

@nano-router/routes

Version:

Objects to setup routes

22 lines (21 loc) 582 B
export class Routes { #routes; constructor(...routes) { this.#routes = routes; } match(path) { for (let i = 0; i < this.#routes.length; i++) { const route = this.#routes[i]; if (route) { const match = route.match(path); if (match) { return { name: route.name, params: match }; } } } return { name: "default", params: {} }; } byName(name) { return this.#routes.find((route) => route.name === name) || null; } }