-
Notifications
You must be signed in to change notification settings - Fork 1
/
HashRouter.ts
33 lines (29 loc) · 914 Bytes
/
HashRouter.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
import { Router } from "../Router/Router";
export class HashRouter extends Router {
public async go(
path: string,
optionalArguments?: GoOptionalArguments
): Promise<void> {
if (optionalArguments && optionalArguments.onBeforeEnter) {
await this.onBeforeEnter(path, optionalArguments.onBeforeEnter);
} else {
await this.onBeforeEnter(path);
}
this.previousPath = this.currentPath;
this.currentPath = path;
location.hash = path;
if (optionalArguments && optionalArguments.onLeave) {
await this.onLeave(this.previousPath, optionalArguments.onLeave);
} else {
await this.onLeave(this.previousPath);
}
if (optionalArguments && optionalArguments.onEnter) {
await this.onEnter(path, optionalArguments.onEnter);
} else {
await this.onEnter(path);
}
this.hookLIst.forEach(async (el) => {
el.toDo();
});
}
}