Skip to content

Commit 8ee76e9

Browse files
Fix rest match with multiple segments
1 parent 1561414 commit 8ee76e9

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

router.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export const exec = (url, route, matches) => {
4343
// segment match:
4444
if (!m && param == val) continue;
4545
// /foo/* match
46-
if (!m && val && flag == '*') continue;
46+
if (!m && val && flag == '*') break;
4747
// segment mismatch / missing required field:
4848
if (!m || (!val && flag != '?' && flag != '*')) return;
4949
rest = flag == '+' || flag == '*';

test/match.test.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ describe('match', () => {
3333
const accurateResult = execPath('/user/2/foo', '/user/:id/*');
3434
expect(accurateResult).toEqual({ path: '/user/2/foo', params: { id: '2' }, id: '2', query: {} });
3535

36+
const accurateResult2 = execPath('/user/2/foo/bar/bob', '/user/:id/*');
37+
expect(accurateResult2).toEqual({ path: '/user/2/foo/bar/bob', params: { id: '2' }, id: '2', query: {} });
38+
3639
const inaccurateResult = execPath('/', '/user/:id/*');
3740
expect(inaccurateResult).toEqual(undefined);
3841
});

0 commit comments

Comments
 (0)