-
Notifications
You must be signed in to change notification settings - Fork 13.5k
/
Copy pathrouter.ts
62 lines (52 loc) · 1.87 KB
/
router.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import { inject } from "vue";
import type { AnimationBuilder } from "../";
export type RouteAction = "push" | "pop" | "replace";
export type RouteDirection = "forward" | "back" | "root" | "none";
export interface UseIonRouterResult {
/**
* The location parameter is really of type 'RouteLocationRaw'
* imported from vue-router, but the @ionic/vue package should
* not have a hard dependency on vue-router, so we just use 'any'.
*/
canGoBack: (deep?: number) => boolean;
push: (location: any, routerAnimation?: AnimationBuilder) => void;
replace: (location: any, routerAnimation?: AnimationBuilder) => void;
back: (routerAnimation?: AnimationBuilder) => void;
forward: (routerAnimation?: AnimationBuilder) => void;
navigate: (
location: any,
routerDirection?: RouteDirection,
routerAction?: RouteAction,
routerAnimation?: AnimationBuilder
) => void;
}
/**
* Used to navigate within Vue Router
* while controlling the animation.
*/
export const useIonRouter = (): UseIonRouterResult => {
const { canGoBack, goBack, goForward, handleNavigate } = inject(
"navManager"
) as any;
const navigate = (
location: any,
routerDirection?: RouteDirection,
routerAction?: RouteAction,
routerAnimation?: AnimationBuilder
) => handleNavigate(location, routerAction, routerDirection, routerAnimation);
const push = (location: any, routerAnimation?: AnimationBuilder) =>
navigate(location, "forward", "push", routerAnimation);
const replace = (location: any, routerAnimation?: AnimationBuilder) =>
navigate(location, "root", "replace", routerAnimation);
const back = (routerAnimation?: AnimationBuilder) => goBack(routerAnimation);
const forward = (routerAnimation?: AnimationBuilder) =>
goForward(routerAnimation);
return {
canGoBack,
push,
replace,
back,
forward,
navigate,
} as UseIonRouterResult;
};