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