From: Eduardo San Martin Morote Date: Wed, 8 Apr 2020 09:40:53 +0000 (+0200) Subject: chore: improve scrolling in playground X-Git-Tag: v4.0.0-alpha.5~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dfa4f1362abaa4cba4e771772606c0f11a9347d7;p=thirdparty%2Fvuejs%2Frouter.git chore: improve scrolling in playground --- diff --git a/playground/router.ts b/playground/router.ts index e8f589d4..ba8bfaec 100644 --- a/playground/router.ts +++ b/playground/router.ts @@ -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 }, }) diff --git a/src/components/Link.ts b/src/components/Link.ts index a487bc47..495f3e5a 100644 --- a/src/components/Link.ts +++ b/src/components/Link.ts @@ -20,6 +20,8 @@ interface LinkProps { type UseLinkOptions = VueUseOptions +// 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 diff --git a/src/router.ts b/src/router.ts index be9b9a14..dcd04858 100644 --- a/src/router.ts +++ b/src/router.ts @@ -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 | Promise + export interface ScrollBehavior { ( to: RouteLocationNormalized, from: RouteLocationNormalizedLoaded, savedPosition: ScrollToPosition | null ): // TODO: implement false nad refactor promise based type - | ScrollPosition - | Promise - | false - | undefined + Awaitable } export interface RouterOptions {