diff --git a/packages/playground/src/App.vue b/packages/playground/src/App.vue index 170d73919..111197c5b 100644 --- a/packages/playground/src/App.vue +++ b/packages/playground/src/App.vue @@ -158,6 +158,15 @@
  • /p_1/absolute-a
  • +
  • + Go to Features (name) +
  • +
  • + Go to Features (string) +
  • +
  • + Go to Feature one +
  • diff --git a/packages/playground/src/router.ts b/packages/playground/src/router.ts index 981b4192f..ba16c9646 100644 --- a/packages/playground/src/router.ts +++ b/packages/playground/src/router.ts @@ -159,6 +159,11 @@ export const router = createRouter({ { path: 'settings', component }, ], }, + { + path: '/features/:pathMatch(.*)*', + name: 'features', + component: User, + }, ], async scrollBehavior(to, from, savedPosition) { await scrollWaiter.wait() diff --git a/packages/router/__tests__/matcher/resolve.spec.ts b/packages/router/__tests__/matcher/resolve.spec.ts index 2b9c4e7ae..7c412083c 100644 --- a/packages/router/__tests__/matcher/resolve.spec.ts +++ b/packages/router/__tests__/matcher/resolve.spec.ts @@ -685,12 +685,12 @@ describe('RouterMatcher.resolve', () => { assertRecordMatch( { path: '/:a?', components, name: 'a' }, { path: '/' }, - { path: '/', params: { a: '' }, name: 'a' } + { path: '/', params: {}, name: 'a' } ) assertRecordMatch( { path: '/a/:a?', components, name: 'a' }, { path: '/a/' }, - { path: '/a/', params: { a: '' }, name: 'a' } + { path: '/a/', params: {}, name: 'a' } ) }) diff --git a/packages/router/src/matcher/index.ts b/packages/router/src/matcher/index.ts index 9d787ddbc..5cfbd5945 100644 --- a/packages/router/src/matcher/index.ts +++ b/packages/router/src/matcher/index.ts @@ -310,6 +310,12 @@ export function createRouterMatcher( // we know the matcher works because we tested the regexp params = matcher.parse(path)! name = matcher.record.name + + matcher?.keys.forEach(key => { + if (key.optional && params[key.name] === '') { + delete params[key.name] + } + }) } // location is a relative path } else {