UNPKG

3.09 kBTypeScriptView Raw
1declare module '@ember/routing/hash-location' {
2 import EmberObject from '@ember/object';
3 import type { default as EmberLocation, UpdateCallback } from '@ember/routing/location';
4 /**
5 @module @ember/routing/hash-location
6 */
7 /**
8 `HashLocation` implements the location API using the browser's
9 hash. At present, it relies on a `hashchange` event existing in the
10 browser.
11
12 Using `HashLocation` results in URLs with a `#` (hash sign) separating the
13 server side URL portion of the URL from the portion that is used by Ember.
14
15 Example:
16
17 ```app/router.js
18 Router.map(function() {
19 this.route('posts', function() {
20 this.route('new');
21 });
22 });
23
24 Router.reopen({
25 location: 'hash'
26 });
27 ```
28
29 This will result in a posts.new url of `/#/posts/new`.
30
31 @class HashLocation
32 @extends EmberObject
33 @protected
34 */
35 export default class HashLocation extends EmberObject implements EmberLocation {
36 _hashchangeHandler?: EventListener;
37 private _location?;
38 location: Location;
39 init(): void;
40 /**
41 @private
42
43 Returns normalized location.hash
44
45 @since 1.5.1
46 @method getHash
47 */
48 getHash(): string;
49 /**
50 Returns the normalized URL, constructed from `location.hash`.
51
52 e.g. `#/foo` => `/foo` as well as `#/foo#bar` => `/foo#bar`.
53
54 By convention, hashed paths must begin with a forward slash, otherwise they
55 are not treated as a path so we can distinguish intent.
56
57 @private
58 @method getURL
59 */
60 getURL(): string;
61 /**
62 Set the `location.hash` and remembers what was set. This prevents
63 `onUpdateURL` callbacks from triggering when the hash was set by
64 `HashLocation`.
65
66 @private
67 @method setURL
68 @param path {String}
69 */
70 setURL(path: string): void;
71 /**
72 Uses location.replace to update the url without a page reload
73 or history modification.
74
75 @private
76 @method replaceURL
77 @param path {String}
78 */
79 replaceURL(path: string): void;
80 lastSetURL: string | null;
81 /**
82 Register a callback to be invoked when the hash changes. These
83 callbacks will execute when the user presses the back or forward
84 button, but not after `setURL` is invoked.
85
86 @private
87 @method onUpdateURL
88 @param callback {Function}
89 */
90 onUpdateURL(callback: UpdateCallback): void;
91 /**
92 Given a URL, formats it to be placed into the page as part
93 of an element's `href` attribute.
94
95 @private
96 @method formatURL
97 @param url {String}
98 */
99 formatURL(url: string): string;
100 /**
101 Cleans up the HashLocation event listener.
102
103 @private
104 @method willDestroy
105 */
106 willDestroy(): void;
107 _removeEventListener(): void;
108 }
109}