@@ -8,21 +8,23 @@ export interface RawParams {
8
8
export type ParamsOrArray = ( RawParams | RawParams [ ] ) ;
9
9
10
10
/**
11
- * Inside the [[StateDeclaration.params]] object of a [[StateDeclaration]]:
12
- * A ParamDeclaration object defines how a single State Parameter should work.
11
+ Inside a [[StateDeclaration.params]]:
13
12
*
14
- * @example ---
13
+ * A ParamDeclaration object defines how a single State Parameter should work.
15
14
*
15
+ * @example
16
16
* ```
17
+ *
17
18
* var mystate = {
18
19
* template: '<div ui-view/>',
19
20
* controller: function() {}
20
21
* url: '/mystate/:param1',
21
22
* params: {
22
- * param1: "index", // Default value for 'param1'
23
+ * param1: "index", // <-- Default value for 'param1'
24
+ * // (shorthand ParamDeclaration)
23
25
*
24
- * nonUrlParam: { // ParamDeclaration for 'nonUrlParam' starts
25
- * type: "int", // non
26
+ * nonUrlParam: { // <-- ParamDeclaration for 'nonUrlParam'
27
+ * type: "int",
26
28
* array: true,
27
29
* value: []
28
30
* }
@@ -32,6 +34,8 @@ export type ParamsOrArray = (RawParams|RawParams[]);
32
34
*/
33
35
export interface ParamDeclaration {
34
36
/**
37
+ * A property of [[ParamDeclaration]]:
38
+ *
35
39
* Specifies the default value for this parameter. This implicitly sets this parameter as optional.
36
40
*
37
41
* When UI-Router routes to a state and no value is specified for this parameter in the URL or transition,
@@ -53,7 +57,8 @@ export interface ParamDeclaration {
53
57
* }
54
58
*```
55
59
*
56
- * Shorthand: If you only need to configure the default value of the parameter, you may use a shorthand syntax.
60
+ * ### Shorthand Declaration
61
+ * If you only want to set the default value of the parameter, you may use a shorthand syntax.
57
62
* In the params map, instead mapping the param name to a full parameter configuration object, simply set map it
58
63
* to the default parameter value, e.g.:
59
64
* ```
@@ -79,33 +84,138 @@ export interface ParamDeclaration {
79
84
value ?: any ;
80
85
81
86
/**
82
- * Specifies the parameter type.
87
+ * A property of [[ParamDeclaration]]:
83
88
*
84
- * Supplying a parameter type
89
+ * Specifies the [[Type]] of the parameter.
90
+ *
91
+ * Set this property to the name of parameter's type. The type may be either one of the
92
+ * built in types, or a custom type that has been registered with the [[$urlMatcherFactory]]
85
93
*/
86
94
type : ( string | Type ) ;
95
+
96
+ /**
97
+ * A property of [[ParamDeclaration]]:
98
+ *
99
+ * Explicitly specifies the array mode of a URL parameter
100
+ *
101
+ * - If `false`, the parameter value will be treated (encoded/decoded) as a single value
102
+ * - If `true`, the parameter value will be treated (encoded/decoded) as an array of values.
103
+ * - If `auto` (for query parameters only), if multiple values for a single parameter are present
104
+ * in the URL (e.g.: /foo?bar=1&bar=2&bar=3) then the values are mapped to an array (e.g.:
105
+ * `{ foo: [ '1', '2', '3' ] }`). However, if only one value is present (e.g.: /foo?bar=1)
106
+ * then the value is treated as single value (e.g.: { foo: '1' }).
107
+ *
108
+
109
+ * If you specified a [[type]] for the parameter, the value will be treated as an array
110
+ * of the specified Type.
111
+ *
112
+ * @example
113
+ * ```
114
+ *
115
+ * {
116
+ * name: 'foo',
117
+ * url: '/foo/{arrayParam:int}`,
118
+ * params: {
119
+ * arrayParam: { array: true }
120
+ * }
121
+ * }
122
+ *
123
+ * // After the transition, URL should be '/foo/1-2-3'
124
+ * $state.go("foo", { arrayParam: [ 1, 2, 3 ] });
125
+ * ```
126
+ *
127
+ * @default `false` for path parameters, such as `url: '/foo/:pathParam'`
128
+ * @default `auto` for query parameters, such as `url: '/foo?queryParam'`
129
+ * @default `true` if the parameter name ends in `[]`, such as `url: '/foo/{implicitArrayParam:int[]}'`
130
+ */
87
131
array : boolean ;
132
+ /**
133
+ * A property of [[ParamDeclaration]]:
134
+ *
135
+ * Configures how a default parameter value is represented in the URL when the current parameter value
136
+ * is the same as the default value.
137
+ *
138
+ * There are three squash settings:
139
+ *
140
+ * - `false`: The parameter's default value is not squashed. It is encoded and included in the URL
141
+ * - `true`: The parameter's default value is omitted from the URL. If the parameter is preceeded
142
+ * and followed by slashes in the state's url declaration, then one of those slashes are omitted.
143
+ * This can allow for cleaner looking URLs.
144
+ * - `"<arbitrary string>"`: The parameter's default value is replaced with an arbitrary
145
+ * placeholder of your choice.
146
+ *
147
+ * @example
148
+ * ```
149
+ *
150
+ * {
151
+ * name: 'mystate',
152
+ * url: '/mystate/:myparam',
153
+ * params: {
154
+ * myparam: 'defaultParamValue'
155
+ * squash: true
156
+ * }
157
+ * }
158
+ *
159
+ * // URL will be `/mystate/`
160
+ * $state.go('mystate', { myparam: 'defaultParamValue' });
161
+ *
162
+ * // URL will be `/mystate/someOtherValue`
163
+ * $state.go('mystate', { myparam: 'someOtherValue' });
164
+ * ```
165
+ *
166
+ * @example
167
+ * ```
168
+ *
169
+ * {
170
+ * name: 'mystate2',
171
+ * url: '/mystate2/:myparam2',
172
+ * params: {
173
+ * myparam2: 'defaultParamValue'
174
+ * squash: "~"
175
+ * }
176
+ * }
177
+ *
178
+ * // URL will be `/mystate/~`
179
+ * $state.go('mystate', { myparam2: 'defaultParamValue' });
180
+ *
181
+ * // URL will be `/mystate/someOtherValue`
182
+ * $state.go('mystate', { myparam2: 'someOtherValue' });
183
+ * ```
184
+ *
185
+ * If squash is not set, it uses the configured default squash policy. (See [[defaultSquashPolicy]]())
186
+ */
88
187
squash : ( boolean | string ) ;
89
- replace : any ;
90
- /** @internal */
188
+ /**
189
+ * @hidden
190
+ * @internalapi
191
+ *
192
+ * An array of [[Replace]] objects.
193
+ *
194
+ * When creating a Transition, defines how to handle certain special values, such as `undefined`, `null`,
195
+ * or empty string `""`. If the transition is started, and the parameter value is equal to one of the "to"
196
+ * values, then the parameter value is replaced with the "from" value.
197
+ *
198
+ * @example
199
+ * ```
200
+ *
201
+ * replace: [
202
+ * { from: undefined, to: null },
203
+ * { from: "", to: null }
204
+ * ]
205
+ */
206
+ replace : Replace [ ] ;
207
+ /**
208
+ * @hidden
209
+ * @internalapi
210
+ *
211
+ * This is not part of the declaration; it is a calculated value depending on if a default value was specified or not.
212
+ */
91
213
isOptional : boolean ;
214
+ /** @todo document this one too */
92
215
dynamic : boolean ;
93
216
}
94
217
95
- /**
96
- * Inside a state definition:
97
- * A nested object named `params` which defines state parameter customizations.
98
- *
99
- * The ParamDeclaration contains configuration for state parameter declarations.
100
- * Keys should be the name of the parameter and values are treated as [[ParamDeclaration]] objects.
101
- *
102
- * #### example:
103
- * ```
104
- * params: {
105
- * folder: {
106
- * value: "index",
107
- * squash: true
108
- * }
109
- * }```
110
- */
111
- export interface ParamsConfig { [ key : string ] : ParamDeclaration }
218
+ interface Replace {
219
+ from : string ,
220
+ to :string
221
+ }
0 commit comments