UNPKG

13.4 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6/**
7 * The router manages the application's routing configuration and dispatches
8 * controllers and views according to the current URL and the route it matches.
9 *
10 * @interface
11 */
12class Router {
13 /**
14 * Initializes the router with the provided configuration.
15 *
16 * @param {{
17 * $Protocol: string,
18 * $Root: string,
19 * $LanguagePartPath: string,
20 * $Host: string
21 * }} config Router configuration.
22 * The {@code $Protocol} field must be the current protocol used to
23 * access the application, terminated by a collon (for example
24 * {@code https:}).
25 * The {@code $Root} field must specify the URL path pointing to the
26 * application's root.
27 * The {@code $LanguagePartPath} field must be the URL path fragment
28 * used as a suffix to the {@code $Root} field that specifies the
29 * current language.
30 * The {@code $Host} field must be the application's domain (and the
31 * port number if other than the default is used) in the following
32 * form: {@code `${protocol}//${host}`}.
33 */
34 init() {}
35
36 /**
37 * Adds a new route to router.
38 *
39 * @param {string} name The unique name of this route, identifying it among
40 * the rest of the routes in the application.
41 * @param {string} pathExpression A path expression specifying the URL path
42 * part matching this route (must not contain a query string),
43 * optionally containing named parameter placeholders specified as
44 * {@code :parameterName}. The name of the parameter is terminated
45 * by a forward slash ({@code /}) or the end of the path expression
46 * string.
47 * The path expression may also contain optional parameters, which
48 * are specified as {@code :?parameterName}. It is recommended to
49 * specify the optional parameters at the end of the path
50 * expression.
51 * @param {string} controller The full name of Object Container alias
52 * identifying the controller associated with this route.
53 * @param {string} view The full name or Object Container alias identifying
54 * the view class associated with this route.
55 * @param {{
56 * onlyUpdate: (
57 * boolean|
58 * function(
59 * (string|function(new: Controller, ...*)),
60 * (string|function(
61 * new: React.Component,
62 * Object<string, *>,
63 * ?Object<string, *>
64 * ))
65 * ): boolean
66 * )=,
67 * autoScroll: boolean=,
68 * allowSPA: boolean=,
69 * documentView: ?function(new: AbstractDocumentView)=,
70 * managedRootView: ?function(new: React.Component)=,
71 * viewAdapter: ?function(new: React.Component)=
72 * }=} options
73 * Additional route options, specified how the navigation to the
74 * route will be handled.
75 * The {@code onlyUpdate} can be either a flag signalling whether
76 * the current controller and view instances should be kept if they
77 * match the ones used by the previous route; or a callback function
78 * that will receive the previous controller and view identifiers
79 * used in the previously matching route, and returns a
80 * {@code boolean} representing the value of the flag. This flag is
81 * disabled by default.
82 * The {@code autoScroll} flag signals whether the page should be
83 * scrolled to the top when the navigation takes place. This flag is
84 * enabled by default.
85 * The {@code allowSPA} flag can be used to make the route
86 * always served from the server and never using the SPA page even
87 * if the server is overloaded. This is useful for routes that use
88 * different document views (specified by the {@code documentView}
89 * option), for example for rendering the content of iframes.
90 * @return {Router} This router.
91 * @throws {ImaError} Thrown if a route with the same name already exists.
92 */
93 add() {}
94
95 /**
96 * Removes the specified route from the router's known routes.
97 *
98 * @param {string} name The route's unique name, identifying the route to
99 * remove.
100 * @return {Router} This router.
101 */
102 remove() {}
103
104 /**
105 * Returns the current path part of the current URL, including the query
106 * string (if any).
107 *
108 * @return {string} The path and query parts of the current URL.
109 */
110 getPath() {}
111
112 /**
113 * Returns the current absolute URL (including protocol, host, query, etc).
114 *
115 * @return {string} The current absolute URL.
116 */
117 getUrl() {}
118
119 /**
120 * Returns the application's absolute base URL, pointing to the public root
121 * of the application.
122 *
123 * @return {string} The application's base URL.
124 */
125 getBaseUrl() {}
126
127 /**
128 * Returns the application's domain in the following form
129 * {@code `${protocol}//${host}`}.
130 *
131 * @return {string} The current application's domain.
132 */
133 getDomain() {}
134
135 /**
136 * Returns application's host (domain and, if necessary, the port number).
137 *
138 * @return {string} The current application's host.
139 */
140 getHost() {}
141
142 /**
143 * Returns the current protocol used to access the application, terminated
144 * by a colon (for example {@code https:}).
145 *
146 * @return {string} The current application protocol used to access the
147 * application.
148 */
149 getProtocol() {}
150
151 /**
152 * Returns the information about the currently active route.
153 *
154 * @return {{
155 * route: Route,
156 * params: Object<string, string>,
157 * path: string
158 * }} The information about the current route.
159 * @throws {ImaError} Thrown if a route is not define for current path.
160 */
161 getCurrentRouteInfo() {}
162
163 /**
164 * Registers event listeners at the client side window object allowing the
165 * router to capture user's history (history pop state - going "back") and
166 * page (clicking links) navigation.
167 *
168 * The router will start processing the navigation internally, handling the
169 * user's navigation to display the page related to the URL resulting from
170 * the user's action.
171 *
172 * Note that the router will not prevent forms from being submitted to the
173 * server.
174 *
175 * The effects of this method cannot be reverted. This method has no effect
176 * at the server side.
177 *
178 * @return {Router} This router.
179 */
180 listen() {}
181
182 /**
183 * Redirects the client to the specified location.
184 *
185 * At the server side the method results in responding to the client with a
186 * redirect HTTP status code and the {@code Location} header.
187 *
188 * At the client side the method updates the current URL by manipulating
189 * the browser history (if the target URL is at the same domain and
190 * protocol as the current one) or performs a hard redirect (if the target
191 * URL points to a different protocol or domain).
192 *
193 * The method will result in the router handling the new URL and routing
194 * the client to the related page if the URL is set at the client side and
195 * points to the same domain and protocol.
196 *
197 * @param {string} url The URL to which the client should be redirected.
198 * @param {{
199 * httpStatus: number=,
200 * onlyUpdate: (
201 * boolean|
202 * function(
203 * (string|function(new: Controller, ...*)),
204 * (string|function(
205 * new: React.Component,
206 * Object<string, *>,
207 * ?Object<string, *>
208 * ))
209 * ): boolean
210 * )=,
211 * autoScroll: boolean=,
212 * allowSPA: boolean=,
213 * documentView: ?AbstractDocumentView=,
214 * managedRootView: ?function(new: React.Component)=,
215 * viewAdapter: ?function(new: React.Component)=
216 * }} [options={}] The options overrides route options defined in
217 * the {@code routes.js} configuration file.
218 */
219 redirect() {}
220
221 /**
222 * Generates an absolute URL (including protocol, domain, etc) for the
223 * specified route by substituting the route's parameter placeholders with
224 * the provided parameter values.
225 *
226 * @param {string} routeName The unique name of the route, identifying the
227 * route to use.
228 * @param {Object<string, string>} params Parameter values for the route's
229 * parameter placeholders. Extraneous parameters will be added as
230 * URL query.
231 * @return {string} An absolute URL for the specified route and parameters.
232 */
233 link() {}
234
235 /**
236 * Routes the application to the route matching the providing path, renders
237 * the route page and sends the result to the client.
238 *
239 * @param {string} path The URL path part received from the client, with
240 * optional query.
241 * @param {{
242 * onlyUpdate: (
243 * boolean|
244 * function(
245 * (string|function(new: Controller, ...*)),
246 * (string|function(
247 * new: React.Component,
248 * Object<string, *>,
249 * ?Object<string, *>
250 * ))
251 * ): boolean
252 * )=,
253 * autoScroll: boolean=,
254 * allowSPA: boolean=,
255 * documentView: ?AbstractDocumentView=,
256 * managedRootView: ?function(new: React.Component)=,
257 * viewAdapter: ?function(new: React.Component)=
258 * }} [options={}] The options overrides route options defined in
259 * the {@code routes.js} configuration file.
260 * @return {Promise<Object<string, *>>} A promise resolved
261 * when the error has been handled and the response has been sent
262 * to the client, or displayed if used at the client side.
263 */
264 route() {}
265
266 /**
267 * Handles an internal server error by responding with the appropriate
268 * "internal server error" error page.
269 *
270 * @param {Object<string, (Error|string)>} params Parameters extracted from
271 * the current URL path and query.
272 * @param {{
273 * onlyUpdate: (
274 * boolean|
275 * function(
276 * (string|function(new: Controller, ...*)),
277 * (string|function(
278 * new: React.Component,
279 * Object<string, *>,
280 * ?Object<string, *>
281 * ))
282 * ): boolean
283 * )=,
284 * autoScroll: boolean=,
285 * serverSPA: boolean=,
286 * documentView: ?AbstractDocumentView=,
287 * managedRootView: ?function(new: React.Component)=,
288 * viewAdapter: ?function(new: React.Component)=
289 * }} [options={}] The options overrides route options defined in
290 * the {@code routes.js} configuration file.
291 * @return {Promise<Object<string, *>>} A promise resolved when the error
292 * has been handled and the response has been sent to the client,
293 * or displayed if used at the client side.
294 */
295 handleError() {}
296
297 /**
298 * Handles a "not found" error by responding with the appropriate "not
299 * found" error page.
300 *
301 * @param {Object<string, (Error|string)>} params Parameters extracted from
302 * the current URL path and query.
303 * @param {{
304 * onlyUpdate: (
305 * boolean|
306 * function(
307 * (string|function(new: Controller, ...*)),
308 * (string|function(
309 * new: React.Component,
310 * Object<string, *>,
311 * ?Object<string, *>
312 * ))
313 * ): boolean
314 * )=,
315 * autoScroll: boolean=,
316 * allowSPA: boolean=,
317 * documentView: ?AbstractDocumentView=,
318 * managedRootView: ?function(new: React.Component),
319 * viewAdapter: ?function(new: React.Component)
320 * }} [options={}] The options overrides route options defined in
321 * the {@code routes.js} configuration file.
322 * @return {Promise<Object<string, *>>} A promise resolved
323 * when the error has been handled and the response has been sent
324 * to the client, or displayed if used at the client side.
325 */
326 handleNotFound() {}
327
328 /**
329 * Tests, if possible, whether the specified error was caused by the
330 * client's action (for example wrong URL or request encoding) or by a
331 * failure at the server side.
332 *
333 * @param {(ImaError|Error)} reason The encountered error.
334 * @return {boolean} {@code true} if the error was caused the action of the
335 * client.
336 */
337 isClientError() {}
338
339 /**
340 * Tests, if possible, whether the specified error lead to redirection.
341 *
342 * @param {(ImaError|Error)} reason The encountered error.
343 * @return {boolean} {@code true} if the error was caused the action of the
344 * redirection.
345 */
346 isRedirection() {}
347}
348exports.default = Router;
349
350typeof $IMA !== 'undefined' && $IMA !== null && $IMA.Loader && $IMA.Loader.register('ima/router/Router', [], function (_export, _context) {
351 'use strict';
352 return {
353 setters: [],
354 execute: function () {
355 _export('default', exports.default);
356 }
357 };
358});