Skip to content

Commit add6ce9

Browse files
committed
feat(router): expose currentLocation param in resolve
1 parent a4d783f commit add6ce9

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

__tests__/router.spec.ts

+16
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,22 @@ describe('Router', () => {
335335
})
336336
})
337337

338+
it('can pass a currentLocation to resolve', async () => {
339+
const { router } = await newRouter()
340+
expect(router.resolve({ params: { p: 1 } })).toMatchObject({
341+
path: '/',
342+
})
343+
expect(
344+
router.resolve(
345+
{ params: { p: 1 } },
346+
router.resolve({ name: 'Param', params: { p: 2 } })
347+
)
348+
).toMatchObject({
349+
name: 'Param',
350+
params: { p: '1' },
351+
})
352+
})
353+
338354
it('resolves relative locations', async () => {
339355
const { router } = await newRouter()
340356
await router.push('/users/posva')

src/router.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -221,11 +221,16 @@ export interface Router {
221221
/**
222222
* Returns the {@link RouteLocation | normalized version} of a
223223
* {@link RouteLocationRaw | route location}. Also includes an `href` property
224-
* that includes any existing `base`.
224+
* that includes any existing `base`. By default the `currentLocation` used is
225+
* `route.currentRoute` and should only be overriden in advanced use cases.
225226
*
226227
* @param to - Raw route location to resolve
228+
* @param currentLocation - Optional current location to resolve against
227229
*/
228-
resolve(to: RouteLocationRaw): RouteLocation & { href: string }
230+
resolve(
231+
to: RouteLocationRaw,
232+
currentLocation?: RouteLocationNormalizedLoaded
233+
): RouteLocation & { href: string }
229234

230235
/**
231236
* Programmatically navigate to a new URL by pushing an entry in the history

0 commit comments

Comments
 (0)