Skip to content

Commit a1f975f

Browse files
authored
fix(router): parse url using URL for pathname (#196)
1 parent 4229ce0 commit a1f975f

File tree

2 files changed

+3
-8
lines changed

2 files changed

+3
-8
lines changed

src/router.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,10 @@ export function createRouter (opts: CreateRouterOptions = {}): Router {
5151

5252
// Main handle
5353
router.handler = eventHandler((event) => {
54-
// Match route
55-
5654
// Remove query parameters for matching
57-
let path = event.req.url || '/'
58-
const queryUrlIndex = path.lastIndexOf('?')
59-
if (queryUrlIndex > -1) {
60-
path = path.substring(0, queryUrlIndex)
61-
}
55+
const path = new URL(event.req.url || '/', 'http://localhost').pathname
6256

57+
// Match route
6358
const matched = _router.lookup(path)
6459
if (!matched) {
6560
if (opts.preemtive) {

test/router.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ describe('router', () => {
5050
})
5151

5252
it('Handle url with query parameters, include "?" in url path', async () => {
53-
const res = await request.get('/test/?/a?title=test')
53+
const res = await request.get('/test/?/a?title=test&returnTo=/path?foo=bar')
5454
expect(res.status).toEqual(200)
5555
})
5656

0 commit comments

Comments
 (0)