UNPKG

@nano-router/routes

Version:

Objects to setup routes

21 lines (20 loc) 530 B
import { PathPattern } from "@nano-router/path"; export class Route { name; external; #pattern; constructor(name, pattern, external = false) { if (name === "default") { throw new Error("default is a reserved route name"); } this.name = name; this.#pattern = new PathPattern(pattern); this.external = external; } match(path) { return this.#pattern.match(path); } stringify(params) { return this.#pattern.stringify(params); } }