-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.ts
59 lines (42 loc) · 1.48 KB
/
index.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
import {Router} from "@angular/router";
import {NavigationExtras} from "@angular/router/src/router";
export const REFLECT_CLASS: any = {
ROUTER: Object.assign({}, Router)
};
declare module "@angular/router" {
export class Router extends REFLECT_CLASS.ROUTER {
private _sendingData: any;
public navigateByData( data: ReflectRouter.NavigatedData ) : Promise<boolean>;
public getNavigatedData() : any;
}
}
export namespace ReflectRouter {
export interface NavigatedData {
url: Array<any>,
data: any,
extras?: NavigationExtras
}
export function init() : void
{
Router.prototype._sendingData = null;
Router.prototype.navigateByData = function ( data: NavigatedData ) : Promise<boolean> {
if (data.data !== undefined && data.data !== null)
this._sendingData = data.data;
return this.navigate(data.url, data.extras);
};
Router.prototype.getNavigatedData = function () : any {
let data: any = this._sendingData;
if (data)
{
if (Array.isArray(data))
data = Object.assign([], data);
else if (typeof data == "object")
data = Object.assign({}, data);
}
if (data !== null)
this._sendingData = null;
return data;
};
}
}
(() : void => ReflectRouter.init())();