Skip to content

Commit c9c3f71

Browse files
docs(ngRoute): clarify when gets updated
1 parent b6ff8d7 commit c9c3f71

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/ngRoute/route.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ function $RouteProvider(){
3535
*
3636
* * `path` can contain named groups starting with a colon (`:name`). All characters up
3737
* to the next slash are matched and stored in `$routeParams` under the given `name`
38-
* when the route matches.
38+
* after the route is resolved.
3939
* * `path` can contain named groups starting with a star (`*name`). All characters are
40-
* eagerly stored in `$routeParams` under the given `name` when the route matches.
40+
* eagerly stored in `$routeParams` under the given `name` after the route is resolved.
4141
*
4242
* For example, routes like `/color/:color/largecode/*largecode/edit` will match
4343
* `/color/brown/largecode/code/with/slashs/edit` and extract:
@@ -83,7 +83,9 @@ function $RouteProvider(){
8383
* - `factory` - `{string|function}`: If `string` then it is an alias for a service.
8484
* Otherwise if function, then it is {@link api/AUTO.$injector#invoke injected}
8585
* and the return value is treated as the dependency. If the result is a promise, it is resolved
86-
* before its value is injected into the controller.
86+
* before its value is injected into the controller. Be aware that `ngRoute.$routeParams` will
87+
* still refer to the previous route within these resolve functions. Use `$route.current.params`
88+
* to access the new route parameters, instead.
8789
*
8890
* - `redirectTo` – {(string|function())=} – value to update
8991
* {@link ng.$location $location} path with and trigger route redirection.

src/ngRoute/routeParams.js

+4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ ngRouteModule.provider('$routeParams', $RouteParamsProvider);
1818
* The service guarantees that the identity of the `$routeParams` object will remain unchanged
1919
* (but its properties will likely change) even when a route change occurs.
2020
*
21+
* Note that the `$routeParams` are only updated *after* a route change completes successfully.
22+
* This means that you cannot rely on `$routeParams` being correct in route resolve functions.
23+
* Instead you can use `$route.current.params` to access the new route's parameters.
24+
*
2125
* @example
2226
* <pre>
2327
* // Given:

0 commit comments

Comments
 (0)