Skip to content
This repository was archived by the owner on Jul 6, 2025. It is now read-only.

Commit 16cce8b

Browse files
author
Je
committed
refactor: discard params types to Record<string,string>
1 parent ada6367 commit 16cce8b

File tree

5 files changed

+7
-9
lines changed

5 files changed

+7
-9
lines changed

context.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export const RouterContext = createContext<RouterURL>({
55
locale: 'en',
66
pagePath: '/',
77
pathname: '/',
8-
params: new Map(),
8+
params: {},
99
query: new URLSearchParams(),
1010
})
1111
RouterContext.displayName = 'RouterContext'

project.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1272,7 +1272,7 @@ export class Project {
12721272
return ret
12731273
}
12741274

1275-
private async _render404Page(url: RouterURL = { locale: this.config.defaultLocale, pagePath: '', pathname: '/', params: new Map(), query: new URLSearchParams() }) {
1275+
private async _render404Page(url: RouterURL = { locale: this.config.defaultLocale, pagePath: '', pathname: '/', params: {}, query: new URLSearchParams() }) {
12761276
const ret: RenderResult = { url, status: 404, head: [], body: '<main></main>', data: null }
12771277
try {
12781278
const e404Module = this.#modules.get('/404.js')

routing.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ export class Routing {
117117
let locale = this._defaultLocale
118118
let pathname = util.cleanPath(util.trimPrefix(loc.pathname, this._baseUrl))
119119
let pagePath = ''
120-
let params: Map<string, string> = new Map
120+
let params: Record<string, string> = {}
121121
let tree: RouteModule[] = []
122122

123123
if (pathname !== '/' && this._locales.length > 0) {
@@ -139,9 +139,7 @@ export class Routing {
139139
tree.push(c.module)
140140
}
141141
pagePath = path
142-
for (const key in p) {
143-
params.set(key, p[key])
144-
}
142+
params = p
145143
return false
146144
}
147145
}, true)

server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export async function start(appDir: string, port: number, isDev = false, reload
1717
for await (const req of s) {
1818
const url = new URL('http://localhost/' + req.url)
1919
const pathname = util.cleanPath(url.pathname)
20-
const resp = new Request(req, { pathname, params: new Map(), query: new URLSearchParams() })
20+
const resp = new Request(req, { pathname, params: {}, query: new URLSearchParams() })
2121

2222
try {
2323
// serve hmr ws

types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export interface Config {
3030

3131
export interface APIRequestURL {
3232
readonly pathname: string
33-
readonly params: ReadonlyMap<string, string>
33+
readonly params: Record<string, string>
3434
readonly query: URLSearchParams
3535
}
3636

@@ -75,6 +75,6 @@ export interface RouterURL {
7575
readonly locale: string
7676
readonly pathname: string
7777
readonly pagePath: string
78-
readonly params: ReadonlyMap<string, string>
78+
readonly params: Record<string, string>
7979
readonly query: URLSearchParams
8080
}

0 commit comments

Comments
 (0)