-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MSTR-228: Allow app custom routing (#1006)
* Use RegExp to handle optional rest and query segments Use RegExp instead of pattern for app route, because Crossroads.js extracts the query string as part of the rest segment. This is because it does not support having both segments as optional. See: millermedeiros/crossroads.js#130 * Expose utility function parseQueryString * Parse route query string into an object * Reload app only if there is no rest segment * Restrict app name capturing group to expected pattern * Use variables to check custom routing condition
- Loading branch information
1 parent
6ba7ddb
commit d35e17a
Showing
4 changed files
with
122 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
title: parseQueryString() | ||
|
||
# monster.util.parseQueryString() | ||
|
||
## Syntax | ||
```javascript | ||
monster.util.parseQueryString(queryString); | ||
``` | ||
|
||
### Parameters | ||
Key | Description | Type | Default | Required | ||
:-: | --- | :-: | :-: | :-: | ||
`queryString` | Query string to be parsed as an object. | `String` | | `true` | ||
|
||
### Return value | ||
An `Object` representation of the query string parameters. | ||
|
||
## Description | ||
This method parses a query string into an object representation of its parameters. | ||
|
||
All of the parameter values are converted to strings. | ||
|
||
If the parameter key ends with a pair of square brackets, it is interpreted as an array. If an index is specified between the brackets, then the value is added in the specified position. If no index is specified, then the value is added at the end of the array. | ||
|
||
Also, if a parameter key has no square braces, but it is repeated more than once in the query string, it is also interpreted as an array, whose values will be added in the same order as they appear in the string. | ||
|
||
These are valid query string representations of the same array: | ||
|
||
* `'colors=red&colors=blue&colors=yellow'` | ||
* `'colors[]=red&colors[]=blue&colors[]=yellow'` | ||
* `'colors[0]=red&colors[1]=blue&colors[2]=yellow'` | ||
|
||
## Example | ||
```javascript | ||
monster.util.parseQueryString('param1=22¶m2=false¶m3=hello') | ||
// output: { param1: "22", param2: "false", param3: "hello" } | ||
|
||
monster.util.parseQueryString('palette=basic&colors[]=red&colors[]=blue&colors[]=yellow') | ||
// output: { palette: "basic", colors: [ "red", "blue", "yellow" ] } | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters