1 | import { UIRouter } from '../router';
|
2 | import { LocationServices } from '../common';
|
3 | import { MatchResult, UrlParts, UrlSyncApi } from './interface';
|
4 | import { UrlRules } from './urlRules';
|
5 | import { UrlConfig } from './urlConfig';
|
6 |
|
7 |
|
8 |
|
9 | export declare class UrlService implements LocationServices, UrlSyncApi {
|
10 | private router;
|
11 | private _stopListeningFn;
|
12 | interceptDeferred: boolean;
|
13 | |
14 |
|
15 |
|
16 |
|
17 |
|
18 | rules: UrlRules;
|
19 | |
20 |
|
21 |
|
22 |
|
23 |
|
24 | config: UrlConfig;
|
25 |
|
26 | constructor( router: UIRouter);
|
27 | /** @internal */
|
28 | dispose(): void;
|
29 | /**
|
30 | * Gets the current URL parts
|
31 | *
|
32 | * This method returns the different parts of the current URL (the [[path]], [[search]], and [[hash]]) as a [[UrlParts]] object.
|
33 | */
|
34 | parts(): UrlParts;
|
35 | /**
|
36 | * Activates the best rule for the current URL
|
37 | *
|
38 | * Checks the current URL for a matching [[UrlRule]], then invokes that rule's handler.
|
39 | * This method is called internally any time the URL has changed.
|
40 | *
|
41 | * This effectively activates the state (or redirect, etc) which matches the current URL.
|
42 | *
|
43 | * #### Example:
|
44 | * ```js
|
45 | * urlService.deferIntercept();
|
46 | *
|
47 | * fetch('/states.json').then(resp => resp.json()).then(data => {
|
48 | * data.forEach(state => $stateRegistry.register(state));
|
49 | * urlService.listen();
|
50 | *
|
51 | * urlService.sync();
|
52 | * });
|
53 | * ```
|
54 | */
|
55 | sync(evt?: any): void;
|
56 | /**
|
57 | * Starts or stops listening for URL changes
|
58 | *
|
59 | * Call this sometime after calling [[deferIntercept]] to start monitoring the url.
|
60 | * This causes UI-Router to start listening for changes to the URL, if it wasn't already listening.
|
61 | *
|
62 | * If called with `false`, UI-Router will stop listening (call listen(true) to start listening again).
|
63 | *
|
64 | * #### Example:
|
65 | * ```js
|
66 | * urlService.deferIntercept();
|
67 | *
|
68 | * fetch('/states.json').then(resp => resp.json()).then(data => {
|
69 | * data.forEach(state => $stateRegistry.register(state));
|
70 | *
|
71 | * urlService.listen();
|
72 | * urlService.sync();
|
73 | * });
|
74 | * ```
|
75 | *
|
76 | * @param enabled `true` or `false` to start or stop listening to URL changes
|
77 | */
|
78 | listen(enabled?: boolean): Function;
|
79 | /**
|
80 | * Disables monitoring of the URL.
|
81 | *
|
82 | * Call this method before UI-Router has bootstrapped.
|
83 | * It will stop UI-Router from performing the initial url sync.
|
84 | *
|
85 | * This can be useful to perform some asynchronous initialization before the router starts.
|
86 | * Once the initialization is complete, call [[listen]] to tell UI-Router to start watching and synchronizing the URL.
|
87 | *
|
88 | * #### Example:
|
89 | * ```js
|
90 | * // Prevent UI-Router from automatically intercepting URL changes when it starts;
|
91 | * urlService.deferIntercept();
|
92 | *
|
93 | * fetch('/states.json').then(resp => resp.json()).then(data => {
|
94 | * data.forEach(state => $stateRegistry.register(state));
|
95 | * urlService.listen();
|
96 | * urlService.sync();
|
97 | * });
|
98 | * ```
|
99 | *
|
100 | * @param defer Indicates whether to defer location change interception.
|
101 | * Passing no parameter is equivalent to `true`.
|
102 | */
|
103 | deferIntercept(defer?: boolean): void;
|
104 | /**
|
105 | * Matches a URL
|
106 | *
|
107 | * Given a URL (as a [[UrlParts]] object), check all rules and determine the best matching rule.
|
108 | * Return the result as a [[MatchResult]].
|
109 | */
|
110 | match(url: UrlParts): MatchResult;
|
111 | /**
|
112 | * Gets the current url, or updates the url
|
113 | *
|
114 | * ### Getting the current URL
|
115 | *
|
116 | * When no arguments are passed, returns the current URL.
|
117 | * The URL is normalized using the internal [[path]]/[[search]]/[[hash]] values.
|
118 | *
|
119 | * For example, the URL may be stored in the hash ([[HashLocationServices]]) or
|
120 | * have a base HREF prepended ([[PushStateLocationServices]]).
|
121 | *
|
122 | * The raw URL in the browser might be:
|
123 | *
|
124 | * ```
|
125 | * http://mysite.com/somepath/index.html#/internal/path/123?param1=foo#anchor
|
126 | * ```
|
127 | *
|
128 | * or
|
129 | *
|
130 | * ```
|
131 | * http://mysite.com/basepath/internal/path/123?param1=foo#anchor
|
132 | * ```
|
133 | *
|
134 | * then this method returns:
|
135 | *
|
136 | * ```
|
137 | * /internal/path/123?param1=foo#anchor
|
138 | * ```
|
139 | *
|
140 | *
|
141 | * #### Example:
|
142 | * ```js
|
143 | * locationServices.url(); // "/some/path?query=value#anchor"
|
144 | * ```
|
145 | *
|
146 | * ### Updating the URL
|
147 | *
|
148 | * When `newurl` arguments is provided, changes the URL to reflect `newurl`
|
149 | *
|
150 | * #### Example:
|
151 | * ```js
|
152 | * locationServices.url("/some/path?query=value#anchor", true);
|
153 | * ```
|
154 | *
|
155 | * @param newurl The new value for the URL.
|
156 | * This url should reflect only the new internal [[path]], [[search]], and [[hash]] values.
|
157 | * It should not include the protocol, site, port, or base path of an absolute HREF.
|
158 | * @param replace When true, replaces the current history entry (instead of appending it) with this new url
|
159 | * @param state The history's state object, i.e., pushState (if the LocationServices implementation supports it)
|
160 | *
|
161 | * @return the url (after potentially being processed)
|
162 | */
|
163 | url: (newurl?: string, replace?: boolean, state?: any) => string;
|
164 | /**
|
165 | * Gets the path part of the current url
|
166 | *
|
167 | * If the current URL is `/some/path?query=value#anchor`, this returns `/some/path`
|
168 | *
|
169 | * @return the path portion of the url
|
170 | */
|
171 | path: () => string;
|
172 | /**
|
173 | * Gets the search part of the current url as an object
|
174 | *
|
175 | * If the current URL is `/some/path?query=value#anchor`, this returns `{ query: 'value' }`
|
176 | *
|
177 | * @return the search (query) portion of the url, as an object
|
178 | */
|
179 | search: () => {
|
180 | [key: string]: any;
|
181 | };
|
182 | /**
|
183 | * Gets the hash part of the current url
|
184 | *
|
185 | * If the current URL is `/some/path?query=value#anchor`, this returns `anchor`
|
186 | *
|
187 | * @return the hash (anchor) portion of the url
|
188 | */
|
189 | hash: () => string;
|
190 | /**
|
191 | * @internal
|
192 | *
|
193 | * Registers a low level url change handler
|
194 | *
|
195 | * Note: Because this is a low level handler, it's not recommended for general use.
|
196 | *
|
197 | * #### Example:
|
198 | * ```js
|
199 | * let deregisterFn = locationServices.onChange((evt) => console.log("url change", evt));
|
200 | * ```
|
201 | *
|
202 | * @param callback a function that will be called when the url is changing
|
203 | * @return a function that de-registers the callback
|
204 | */
|
205 | onChange: (callback: EventListener) => Function;
|
206 | }
|
207 |
|
\ | No newline at end of file |