Skip to content

Commit 8b3cd3d

Browse files
committed
Prevent unecessary Exception with non-existent links
Closes #1386
1 parent c021235 commit 8b3cd3d

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

src/create-matcher.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export function createMatcher (
3535
const record = nameMap[name]
3636
if (process.env.NODE_ENV !== 'production') {
3737
warn(record, `Route with name '${name}' does not exist`)
38+
return _createRoute(null, location)
3839
}
3940
const paramNames = record.regex.keys
4041
.filter(key => !key.optional)

test/unit/specs/create-matcher.spec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ describe('Creating Matcher', function () {
2121

2222
it('in development, has logged a warning if a named route does not exist', function () {
2323
process.env.NODE_ENV = 'development'
24-
expect(() => {
25-
match({ name: 'bar' }, routes[0]);
26-
}).toThrow(new TypeError('Cannot read property \'regex\' of undefined'));
24+
const { name, matched } = match({ name: 'bar' }, routes[0])
25+
expect(matched.length).toBe(0)
26+
expect(name).toBe('bar')
2727
expect(console.warn).toHaveBeenCalled()
2828
expect(console.warn.calls.argsFor(0)[0]).toMatch('Route with name \'bar\' does not exist');
2929
})

0 commit comments

Comments
 (0)