Skip to content

Commit a739552

Browse files
committed
types for new features
1 parent acaea3b commit a739552

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

flow/declarations.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ declare type NavigationGuard = (
2727

2828
declare type AfterNavigationHook = (to: Route, from: Route) => any
2929

30+
type Position = { x: number, y: number };
31+
3032
declare type RouterOptions = {
3133
routes?: Array<RouteConfig>;
3234
mode?: string;
@@ -38,8 +40,8 @@ declare type RouterOptions = {
3840
scrollBehavior?: (
3941
to: Route,
4042
from: Route,
41-
savedPosition: ?{ x: number, y: number }
42-
) => { x: number, y: number } | { selector: string } | ?{};
43+
savedPosition: ?Position
44+
) => Position | { selector: string, offset?: Position } | ?{};
4345
}
4446

4547
declare type RedirectOption = RawLocation | ((to: Route) => RawLocation)

types/router.d.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,12 @@ declare class VueRouter {
4444
static install: PluginFunction<never>;
4545
}
4646

47+
type Position = { x: number, y: number };
48+
4749
export interface RouterOptions {
4850
routes?: RouteConfig[];
4951
mode?: RouterMode;
52+
fallback?: boolean;
5053
base?: string;
5154
linkActiveClass?: string;
5255
linkExactActiveClass?: string;
@@ -55,8 +58,8 @@ export interface RouterOptions {
5558
scrollBehavior?: (
5659
to: Route,
5760
from: Route,
58-
savedPosition: { x: number, y: number } | undefined
59-
) => { x: number, y: number } | { selector: string } | void;
61+
savedPosition: Position | void
62+
) => Position | { selector: string, offset?: Position } | void;
6063
}
6164

6265
type RoutePropsFunction = (route: Route) => Object;

types/test/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,18 @@ const Hook: ComponentOptions<Vue> = {
4040
const router = new VueRouter({
4141
mode: "history",
4242
base: "/",
43+
fallback: false,
4344
linkActiveClass: "active",
4445
linkExactActiveClass: "exact-active",
4546
scrollBehavior: (to, from, savedPosition) => {
4647
if (from.path === "/") {
4748
return { selector: "#app" };
4849
}
4950

51+
if (from.path === "/offset") {
52+
return { selector: '#foo', offset: { x: 0, y: 100 }}
53+
}
54+
5055
if (to.path === "/child") {
5156
return;
5257
}

0 commit comments

Comments
 (0)