UNPKG

3.74 kBTypeScriptView Raw
1declare module '@ember/routing/history-location' {
2 import EmberObject from '@ember/object';
3 import type { default as EmberLocation, UpdateCallback } from '@ember/routing/location';
4 /**
5 HistoryLocation implements the location API using the browser's
6 history.pushState API.
7
8 Using `HistoryLocation` results in URLs that are indistinguishable from a
9 standard URL. This relies upon the browser's `history` API.
10
11 Example:
12
13 ```app/router.js
14 Router.map(function() {
15 this.route('posts', function() {
16 this.route('new');
17 });
18 });
19
20 Router.reopen({
21 location: 'history'
22 });
23 ```
24
25 This will result in a posts.new url of `/posts/new`.
26
27 Keep in mind that your server must serve the Ember app at all the routes you
28 define.
29
30 Using `HistoryLocation` will also result in location states being recorded by
31 the browser `history` API with the following schema:
32
33 ```
34 window.history.state -> { path: '/', uuid: '3552e730-b4a6-46bd-b8bf-d8c3c1a97e0a' }
35 ```
36
37 This allows each in-app location state to be tracked uniquely across history
38 state changes via the `uuid` field.
39
40 @class HistoryLocation
41 @extends EmberObject
42 @protected
43 */
44 export default class HistoryLocation extends EmberObject implements EmberLocation {
45 location: Location;
46 baseURL: string;
47 history?: Window['history'];
48 _previousURL?: string;
49 _popstateHandler?: EventListener;
50 /**
51 Will be pre-pended to path upon state change
52
53 @property rootURL
54 @default '/'
55 @private
56 */
57 rootURL: string;
58 /**
59 @private
60
61 Returns normalized location.hash
62
63 @method getHash
64 */
65 getHash(): string;
66 init(): void;
67 /**
68 Used to set state on first call to setURL
69
70 @private
71 @method initState
72 */
73 initState(): void;
74 /**
75 Returns the current `location.pathname` without `rootURL` or `baseURL`
76
77 @private
78 @method getURL
79 @return url {String}
80 */
81 getURL(): string;
82 /**
83 Uses `history.pushState` to update the url without a page reload.
84
85 @private
86 @method setURL
87 @param path {String}
88 */
89 setURL(path: string): void;
90 /**
91 Uses `history.replaceState` to update the url without a page reload
92 or history modification.
93
94 @private
95 @method replaceURL
96 @param path {String}
97 */
98 replaceURL(path: string): void;
99 /**
100 Pushes a new state.
101
102 @private
103 @method pushState
104 @param path {String}
105 */
106 pushState(path: string): void;
107 /**
108 Replaces the current state.
109
110 @private
111 @method replaceState
112 @param path {String}
113 */
114 replaceState(path: string): void;
115 /**
116 Register a callback to be invoked whenever the browser
117 history changes, including using forward and back buttons.
118
119 @private
120 @method onUpdateURL
121 @param callback {Function}
122 */
123 onUpdateURL(callback: UpdateCallback): void;
124 /**
125 Formats url to be placed into href attribute.
126
127 @private
128 @method formatURL
129 @param url {String}
130 @return formatted url {String}
131 */
132 formatURL(url: string): string;
133 /**
134 Cleans up the HistoryLocation event listener.
135
136 @private
137 @method willDestroy
138 */
139 willDestroy(): void;
140 _removeEventListener(): void;
141 }
142}