From ddc6bc79777343b3f3c5048f0f21da4a894c037f Mon Sep 17 00:00:00 2001 From: Yusuke Iinuma Date: Mon, 30 Dec 2019 17:00:43 +0900 Subject: [PATCH] fix: suppress warning if `pathMatch` is empty (#3081) Fix #3072 --- src/util/params.js | 3 ++- test/unit/specs/create-matcher.spec.js | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/util/params.js b/src/util/params.js index cac6a683d..e54866ed7 100644 --- a/src/util/params.js +++ b/src/util/params.js @@ -25,7 +25,8 @@ export function fillParams ( return filler(params, { pretty: true }) } catch (e) { if (process.env.NODE_ENV !== 'production') { - warn(false, `missing param for ${routeMsg}: ${e.message}`) + // Fix #3072 no warn if `pathMatch` is string + warn(typeof params.pathMatch === 'string', `missing param for ${routeMsg}: ${e.message}`) } return '' } finally { diff --git a/test/unit/specs/create-matcher.spec.js b/test/unit/specs/create-matcher.spec.js index 88fb475a1..bb0d4fdc3 100644 --- a/test/unit/specs/create-matcher.spec.js +++ b/test/unit/specs/create-matcher.spec.js @@ -71,6 +71,15 @@ describe('Creating Matcher', function () { expect(path).toEqual('/error/some') }) + it('matches named catch-all route with empty pathMath param without warning', function () { + process.env.NODE_ENV = 'development' + match( + { name: 'notFound', params: { pathMatch: '' }}, + routes[0] + ) + expect(console.warn).not.toHaveBeenCalled() + }) + it('matches asterisk routes with a default param name', function () { const { params } = match({ path: '/not-found' }, routes[0]) expect(params).toEqual({ pathMatch: '/not-found' })