aboutsummaryrefslogtreecommitdiffstats
path: root/src/ng/route.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/ng/route.js')
-rw-r--r--src/ng/route.js30
1 files changed, 23 insertions, 7 deletions
diff --git a/src/ng/route.js b/src/ng/route.js
index 971caa1c..afdac3fb 100644
--- a/src/ng/route.js
+++ b/src/ng/route.js
@@ -23,9 +23,18 @@ function $RouteProvider(){
* `$location.path` will be updated to add or drop the trailing slash to exactly match the
* route definition.
*
- * `path` can contain named groups starting with a colon (`:name`). All characters up to the
- * next slash are matched and stored in `$routeParams` under the given `name` when the route
- * matches.
+ * * `path` can contain named groups starting with a colon (`:name`). All characters up
+ * to the next slash are matched and stored in `$routeParams` under the given `name`
+ * when the route matches.
+ * * `path` can contain named groups starting with a star (`*name`). All characters are
+ * eagerly stored in `$routeParams` under the given `name` when the route matches.
+ *
+ * For example, routes like `/color/:color/largecode/*largecode/edit` will match
+ * `/color/brown/largecode/code/with/slashs/edit` and extract:
+ *
+ * * `color: brown`
+ * * `largecode: code/with/slashs`.
+ *
*
* @param {Object} route Mapping information to be assigned to `$route.current` on route
* match.
@@ -341,12 +350,12 @@ function $RouteProvider(){
// regex only once and then reuse it
// Escape regexp special characters.
- when = '^' + when.replace(/[-\/\\^$*+?.()|[\]{}]/g, "\\$&") + '$';
+ when = '^' + when.replace(/[-\/\\^$:*+?.()|[\]{}]/g, "\\$&") + '$';
var regex = '',
params = [],
dst = {};
- var re = /:(\w+)/g,
+ var re = /\\([:*])(\w+)/g,
paramMatch,
lastMatchedIndex = 0;
@@ -354,8 +363,15 @@ function $RouteProvider(){
// Find each :param in `when` and replace it with a capturing group.
// Append all other sections of when unchanged.
regex += when.slice(lastMatchedIndex, paramMatch.index);
- regex += '([^\\/]*)';
- params.push(paramMatch[1]);
+ switch(paramMatch[1]) {
+ case ':':
+ regex += '([^\\/]*)';
+ break;
+ case '*':
+ regex += '(.*)';
+ break;
+ }
+ params.push(paramMatch[2]);
lastMatchedIndex = re.lastIndex;
}
// Append trailing path part.