From 35e323205f3f9577eb27cdcea25aaf96983e72ff Mon Sep 17 00:00:00 2001 From: pk Date: Wed, 11 Sep 2024 00:19:47 +0200 Subject: [PATCH] Make router work with version 8 of path-to-regex --- package.json | 2 +- tp-router.js | 8 +++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index f25c2a4..6e7a2cb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@tp/tp-router", - "version": "1.0.6", + "version": "1.1.0", "description": "", "main": "tp-router.js", "scripts": { diff --git a/tp-router.js b/tp-router.js index 55f50f1..4232446 100644 --- a/tp-router.js +++ b/tp-router.js @@ -164,7 +164,7 @@ export class TpRouter extends LitElement { if (path === '*') { this._catchAllRoute = { path: path, - regex: pathToRegexp('(.*)'), + regex: pathToRegexp('{/*path}'), data: data, params: {} } @@ -183,9 +183,7 @@ export class TpRouter extends LitElement { this.routes[namespace] = {}; } - const keys = []; - const parsed = pathToRegexp(path, keys); - parsed.keys = keys; + const parsed = pathToRegexp(path); this.routes[namespace][path] = { path: path, @@ -322,7 +320,7 @@ export class TpRouter extends LitElement { const params = route.params = {}; const qsIndex = path.indexOf('?'); const pathname = qsIndex > -1 ? path.slice(0, qsIndex) : path; - const m = route.regex.exec(decodeURIComponent(pathname)); + const m = route.regex.regexp.exec(decodeURIComponent(pathname)); if (!m) return false; for (let i = 1, len = m.length; i < len; ++i) {