diff --git a/__tests__/router.spec.ts b/__tests__/router.spec.ts index e8f49c91b..ca4d59800 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 e87be1237..a6d094a00 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