From 38e6ccd7757bfdf333bb32a1e496e4359b8ec00f Mon Sep 17 00:00:00 2001 From: adi-zz Date: Wed, 29 Jan 2020 19:17:50 +0200 Subject: [PATCH] fix: correctly calculate `path` when `pathMatch` is empty string (#3111) fix #3106 --- src/util/params.js | 3 ++- test/unit/specs/create-matcher.spec.js | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/util/params.js b/src/util/params.js index e54866ed7..83d4aa11a 100644 --- a/src/util/params.js +++ b/src/util/params.js @@ -20,7 +20,8 @@ export function fillParams ( (regexpCompileCache[path] = Regexp.compile(path)) // Fix #2505 resolving asterisk routes { name: 'not-found', params: { pathMatch: '/not-found' }} - if (params.pathMatch) params[0] = params.pathMatch + // and fix #3106 so that you can work with location descriptor object having params.pathMatch equal to empty string + if (typeof params.pathMatch === 'string') params[0] = params.pathMatch return filler(params, { pretty: true }) } catch (e) { diff --git a/test/unit/specs/create-matcher.spec.js b/test/unit/specs/create-matcher.spec.js index bb0d4fdc3..b6d79e5ae 100644 --- a/test/unit/specs/create-matcher.spec.js +++ b/test/unit/specs/create-matcher.spec.js @@ -84,4 +84,20 @@ describe('Creating Matcher', function () { const { params } = match({ path: '/not-found' }, routes[0]) expect(params).toEqual({ pathMatch: '/not-found' }) }) + + it('allows an empty pathMatch', function () { + process.env.NODE_ENV = 'development' + const pathForErrorRoute = match( + { name: 'error', params: { pathMatch: '' }}, + routes[0] + ).path + const pathForNotFoundRoute = match( + { name: 'notFound', params: { pathMatch: '' }}, + routes[0] + ).path + + expect(console.warn).not.toHaveBeenCalled() + expect(pathForErrorRoute).toEqual('/error/') + expect(pathForNotFoundRoute).toEqual('/') + }) })