]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
chore: improve scrolling in playground
authorEduardo San Martin Morote <posva13@gmail.com>
Wed, 8 Apr 2020 09:40:53 +0000 (11:40 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Wed, 8 Apr 2020 09:40:53 +0000 (11:40 +0200)
playground/router.ts
src/components/Link.ts
src/router.ts

index e8f589d4efb1c318ffb65a010af319a03b207635..ba8bfaec481a2f93ea8b680a5ad8a2946b6c89f8 100644 (file)
@@ -133,8 +133,13 @@ export const router = createRouter({
     if (savedPosition) {
       return savedPosition
     } else {
-      return { x: 0, y: 0 }
+      // TODO: check if parent in common that works with alias
+      if (to.matched.every((record, i) => from.matched[i] !== record))
+        return { x: 0, y: 0 }
     }
+    // leave scroll as it is by not returning anything
+    // https://github.com/Microsoft/TypeScript/issues/18319
+    return false
   },
 })
 
index a487bc47b6abe367d5fc428c9decdeae3a141ff4..495f3e5a31fe7e472cacf837e610648c9cf55cd8 100644 (file)
@@ -20,6 +20,8 @@ interface LinkProps {
 
 type UseLinkOptions = VueUseOptions<LinkProps>
 
+// TODO: we could allow currentRoute as a prop to expose `isActive` and
+// `isExactActive` behavior should go through an RFC
 export function useLink(props: UseLinkOptions) {
   const router = inject(routerKey)!
   const currentRoute = router.currentRoute
index be9b9a14bd511934492cc9f375025f243c9aa10f..dcd04858c8f2a16a68b328ef276f9182f8269b79 100644 (file)
@@ -60,16 +60,15 @@ export type ErrorHandler = (error: any) => any
 // resolve, reject arguments of Promise constructor
 type OnReadyCallback = [() => void, (reason?: any) => void]
 
+type Awaitable<T> = T | Promise<T>
+
 export interface ScrollBehavior {
   (
     to: RouteLocationNormalized,
     from: RouteLocationNormalizedLoaded,
     savedPosition: ScrollToPosition | null
   ): // TODO: implement false nad refactor promise based type
-  | ScrollPosition
-    | Promise<ScrollPosition | false | undefined>
-    | false
-    | undefined
+  Awaitable<ScrollPosition | false | void>
 }
 
 export interface RouterOptions {