Skip to content

Commit

Permalink
feat(router): expose currentLocation param in resolve
Browse files Browse the repository at this point in the history
  • Loading branch information
posva committed Mar 26, 2021
1 parent a4d783f commit add6ce9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
16 changes: 16 additions & 0 deletions __tests__/router.spec.ts
Expand Up @@ -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')
Expand Down
9 changes: 7 additions & 2 deletions src/router.ts
Expand Up @@ -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
Expand Down

0 comments on commit add6ce9

Please sign in to comment.