UNPKG

5.54 kBTypeScriptView Raw
1import { Disposable } from '../interface';
2import { UIRouter } from '../router';
3import { ParamTypeDefinition, ParamTypes } from '../params';
4/**
5 * An API to customize the URL behavior and retrieve URL configuration
6 *
7 * This API is used to customize the behavior of the URL.
8 * This includes optional trailing slashes ([[strictMode]]), case sensitivity ([[caseInsensitive]]),
9 * and custom parameter encoding (custom [[type]]).
10 *
11 * It also has information about the location (url) configuration such as [[port]] and [[baseHref]].
12 * This information can be used to build absolute URLs, such as
13 * `https://example.com:443/basepath/state/substate?param1=a#hashvalue`;
14 *
15 * This API is found at `router.urlService.config` (see: [[UIRouter.urlService]], [[URLService.config]])
16 */
17export declare class UrlConfig implements Disposable {
18 private router;
19 /** @internal */ paramTypes: ParamTypes;
20 /** @internal */ _decodeParams: boolean;
21 /** @internal */ _isCaseInsensitive: boolean;
22 /** @internal */ _isStrictMode: boolean;
23 /** @internal */ _defaultSquashPolicy: boolean | string;
24 /** @internal */ constructor(/** @internal */ router: UIRouter);
25 /** @internal */ dispose: () => void;
26 /**
27 * Gets the base Href, e.g., `http://localhost/approot/`
28 *
29 * @return the application's base href
30 */
31 baseHref: () => string;
32 /**
33 * Gets or sets the hashPrefix
34 *
35 * This only applies when not running in [[html5Mode]] (pushstate mode)
36 *
37 * If the current url is `http://localhost/app#!/uirouter/path/#anchor`, it returns `!` which is the prefix for the "hashbang" portion.
38 *
39 * @return the hash prefix
40 */
41 hashPrefix: (newprefix?: string) => string;
42 /**
43 * Gets the host, e.g., `localhost`
44 *
45 * @return the protocol
46 */
47 host: () => string;
48 /**
49 * Returns true when running in pushstate mode
50 *
51 * @return true when running in html5 mode (pushstate mode).
52 */
53 html5Mode: () => boolean;
54 /**
55 * Gets the port, e.g., `80`
56 *
57 * @return the port number
58 */
59 port: () => number;
60 /**
61 * Gets the protocol, e.g., `http`
62 *
63 * @return the protocol
64 */
65 protocol: () => string;
66 /**
67 * Defines whether URL matching should be case sensitive (the default behavior), or not.
68 *
69 * #### Example:
70 * ```js
71 * // Allow case insensitive url matches
72 * urlService.config.caseInsensitive(true);
73 * ```
74 *
75 * @param value `false` to match URL in a case sensitive manner; otherwise `true`;
76 * @returns the current value of caseInsensitive
77 */
78 caseInsensitive(value?: boolean): boolean;
79 /**
80 * Sets the default behavior when generating or matching URLs with default parameter values.
81 *
82 * #### Example:
83 * ```js
84 * // Remove default parameter values from the url
85 * urlService.config.defaultSquashPolicy(true);
86 * ```
87 *
88 * @param value A string that defines the default parameter URL squashing behavior.
89 * - `nosquash`: When generating an href with a default parameter value, do not squash the parameter value from the URL
90 * - `slash`: When generating an href with a default parameter value, squash (remove) the parameter value, and, if the
91 * parameter is surrounded by slashes, squash (remove) one slash from the URL
92 * - any other string, e.g. "~": When generating an href with a default parameter value, squash (remove)
93 * the parameter value from the URL and replace it with this string.
94 * @returns the current value of defaultSquashPolicy
95 */
96 defaultSquashPolicy(value?: boolean | string): string | boolean;
97 /**
98 * Defines whether URLs should match trailing slashes, or not (the default behavior).
99 *
100 * #### Example:
101 * ```js
102 * // Allow optional trailing slashes
103 * urlService.config.strictMode(false);
104 * ```
105 *
106 * @param value `false` to match trailing slashes in URLs, otherwise `true`.
107 * @returns the current value of strictMode
108 */
109 strictMode(value?: boolean): boolean;
110 /**
111 * Creates and registers a custom [[ParamType]] object
112 *
113 * A custom parameter type can be used to generate URLs with typed parameters or custom encoding/decoding.
114 *
115 * #### Note: Register custom types *before using them* in a state definition.
116 *
117 * #### Example:
118 * ```js
119 * // Encode object parameter as JSON string
120 * urlService.config.type('myjson', {
121 * encode: (obj) => JSON.stringify(obj),
122 * decode: (str) => JSON.parse(str),
123 * is: (val) => typeof(val) === 'object',
124 * pattern: /[^/]+/,
125 * equals: (a, b) => _.isEqual(a, b),
126 * });
127 * ```
128 *
129 * See [[ParamTypeDefinition]] for more examples
130 *
131 * @param name The type name.
132 * @param definition The type definition. See [[ParamTypeDefinition]] for information on the values accepted.
133 * @param definitionFn A function that is injected before the app runtime starts.
134 * The result of this function should be a [[ParamTypeDefinition]].
135 * The result is merged into the existing `definition`.
136 * See [[ParamType]] for information on the values accepted.
137 *
138 * @returns if only the `name` parameter was specified: the currently registered [[ParamType]] object, or undefined
139 */
140 type(name: string, definition?: ParamTypeDefinition, definitionFn?: () => ParamTypeDefinition): any;
141}