about summary refs log tree commit diff
path: root/src/lib/routes/router.ts
diff options
context:
space:
mode:
authorSamuel Newman <mozzius@protonmail.com>2025-06-11 20:12:05 +0300
committerGitHub <noreply@github.com>2025-06-11 10:12:05 -0700
commit7341294df6156afdf24ab43e1e27ebba94f265ad (patch)
tree2d1e74054f82c3238a4bfcbf55121124dd079e34 /src/lib/routes/router.ts
parent269105371b22f2de6e8017862a783aaec340948b (diff)
downloadvoidsky-7341294df6156afdf24ab43e1e27ebba94f265ad.tar.zst
Fix using screen names in `Link` (#8473)
* use our router in favour of useLinkBuilder

* test feature using Home header feeds button

* handle non-string params properly
Diffstat (limited to 'src/lib/routes/router.ts')
-rw-r--r--src/lib/routes/router.ts8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/lib/routes/router.ts b/src/lib/routes/router.ts
index 45f9c85fd..ba76b1bda 100644
--- a/src/lib/routes/router.ts
+++ b/src/lib/routes/router.ts
@@ -1,4 +1,4 @@
-import {Route, RouteParams} from './types'
+import {type Route, type RouteParams} from './types'
 
 export class Router {
   routes: [string, Route][] = []
@@ -45,7 +45,7 @@ function createRoute(pattern: string): Route {
   })
   const matcherRe = new RegExp(`^${matcherReInternal}([?]|$)`, 'i')
   return {
-    match(path: string) {
+    match(path) {
       const {pathname, searchParams} = new URL(path, 'http://throwaway.com')
       const addedParams = Object.fromEntries(searchParams.entries())
 
@@ -55,10 +55,10 @@ function createRoute(pattern: string): Route {
       }
       return undefined
     },
-    build(params: Record<string, string>) {
+    build(params = {}) {
       const str = pattern.replace(
         /:([\w]+)/g,
-        (_m, name) => params[name] || 'undefined',
+        (_m, name) => params[encodeURIComponent(name)] || 'undefined',
       )
 
       let hasQp = false