Skip to content

Commit

Permalink
Merge query string into params
Browse files Browse the repository at this point in the history
  • Loading branch information
bringking committed Jul 26, 2018
1 parent 08e8bbe commit 862465e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class Routes {
if (result.route) return result
const params = route.match(pathname)
if (!params) return result
return {...result, route, params, query: {...query, ...params}}
return {...result, route, params: {...query, ...params}, query: {...query, ...params}}
}, {query, parsedUrl})
}

Expand Down
6 changes: 6 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ describe('Routes', () => {
setup('index', '/').testRoute({page: '/'})
})

test('merge query string into params', () => {
const routes = nextRoutes().add('a', '/a/:slug/reviews')
const {params} = routes.match('/a/some-slug/reviews?page=1')
expect(params).toMatchObject({slug: 'some-slug', page: '1'})
})

test('match and merge params into query', () => {
const routes = nextRoutes().add('a').add('b', '/:a?/b/:b').add('c')
const {query} = routes.match('/b/b?b=x&c=c')
Expand Down

0 comments on commit 862465e

Please sign in to comment.