diff options
author | Samuel Newman <mozzius@protonmail.com> | 2025-06-11 20:12:05 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-06-11 10:12:05 -0700 |
commit | 7341294df6156afdf24ab43e1e27ebba94f265ad (patch) | |
tree | 2d1e74054f82c3238a4bfcbf55121124dd079e34 /src/lib/routes | |
parent | 269105371b22f2de6e8017862a783aaec340948b (diff) | |
download | voidsky-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')
-rw-r--r-- | src/lib/routes/router.ts | 8 | ||||
-rw-r--r-- | src/lib/routes/types.ts | 2 |
2 files changed, 5 insertions, 5 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 diff --git a/src/lib/routes/types.ts b/src/lib/routes/types.ts index 6f102d438..f58742390 100644 --- a/src/lib/routes/types.ts +++ b/src/lib/routes/types.ts @@ -143,5 +143,5 @@ export type RouteParams = Record<string, string> export type MatchResult = {params: RouteParams} export type Route = { match: (path: string) => MatchResult | undefined - build: (params: RouteParams) => string + build: (params?: Record<string, any>) => string } |