From: Eduardo San Martin Morote Date: Fri, 26 Mar 2021 10:35:48 +0000 (+0100) Subject: feat(router): expose currentLocation param in resolve X-Git-Tag: v4.0.6~10 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=add6ce9677ffd2c636e215ffab5ddbdef22b0158;p=thirdparty%2Fvuejs%2Frouter.git feat(router): expose currentLocation param in resolve --- diff --git a/__tests__/router.spec.ts b/__tests__/router.spec.ts index e8f49c91..ca4d5980 100644 --- a/__tests__/router.spec.ts +++ b/__tests__/router.spec.ts @@ -335,6 +335,22 @@ describe('Router', () => { }) }) + it('can pass a currentLocation to resolve', async () => { + const { router } = await newRouter() + expect(router.resolve({ params: { p: 1 } })).toMatchObject({ + path: '/', + }) + expect( + router.resolve( + { params: { p: 1 } }, + router.resolve({ name: 'Param', params: { p: 2 } }) + ) + ).toMatchObject({ + name: 'Param', + params: { p: '1' }, + }) + }) + it('resolves relative locations', async () => { const { router } = await newRouter() await router.push('/users/posva') diff --git a/src/router.ts b/src/router.ts index e87be123..a6d094a0 100644 --- a/src/router.ts +++ b/src/router.ts @@ -221,11 +221,16 @@ export interface Router { /** * Returns the {@link RouteLocation | normalized version} of a * {@link RouteLocationRaw | route location}. Also includes an `href` property - * that includes any existing `base`. + * that includes any existing `base`. By default the `currentLocation` used is + * `route.currentRoute` and should only be overriden in advanced use cases. * * @param to - Raw route location to resolve + * @param currentLocation - Optional current location to resolve against */ - resolve(to: RouteLocationRaw): RouteLocation & { href: string } + resolve( + to: RouteLocationRaw, + currentLocation?: RouteLocationNormalizedLoaded + ): RouteLocation & { href: string } /** * Programmatically navigate to a new URL by pushing an entry in the history