Skip to content

Commit b0c0e1f

Browse files
committed
Added extractQuery for routing parsing
1 parent 66b3305 commit b0c0e1f

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

src/routing/api.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,24 @@ function makeMatcherWithoutParams(route) {
4343
extractQuery,
4444
}
4545
}
46+
47+
function extractQuery(path) {
48+
const queryIndex = path.indexOf('?');
49+
50+
if (queryIndex === -1) {
51+
return {};
52+
}
53+
54+
const search = new URLSearchParams(path.slice(queryIndex + 1));
55+
56+
return Object.entries(search.entries());
57+
}
58+
59+
// const route = { path: '/home' }
60+
// const matcher = makeMatcherWithoutParams(route)
61+
62+
// matcher.checkMatch('/users') // false
63+
// matcher.checkMatch('/home') // true
64+
65+
// matcher.extractQuery('/home') // {}
66+
// matcher.extractQuery('/home?tab=profile') // { tab: 'profile' }

0 commit comments

Comments
 (0)