]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
feat(router): expose currentLocation param in resolve
authorEduardo San Martin Morote <posva13@gmail.com>
Fri, 26 Mar 2021 10:35:48 +0000 (11:35 +0100)
committerEduardo San Martin Morote <posva13@gmail.com>
Fri, 26 Mar 2021 10:35:48 +0000 (11:35 +0100)
__tests__/router.spec.ts
src/router.ts

index e8f49c91bb991af8aca87351520852d44814ff88..ca4d59800fb28c20e9cc6a8841e3b2a08613c942 100644 (file)
@@ -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')
index e87be12377983d3e5e072254b6c2d91d4c0d05e0..a6d094a00758754923c2e24c93f5bd0f9a0ca260 100644 (file)
@@ -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