Skip to content

Commit 1364a13

Browse files
committed
docs(urlRouter): updates urlRouter docs
replaced the example with a much better one also improves .sync() method docs
1 parent 929eacc commit 1364a13

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

src/urlRouter.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -243,14 +243,23 @@ function $UrlRouterProvider( $urlMatcherFactory) {
243243
* @methodOf ui.router.router.$urlRouter
244244
*
245245
* @description
246-
* Checks registered rules until first rule is handled.
246+
* Triggers an update; the same update that happens when the address bar url changes, aka `$locationChangeSuccess`.
247+
* This method is useful when you need to use `preventDefault()` on the `$locationChangeSuccess` event,
248+
* perform some custom logic (route protection, auth, config, redirection, etc) and then finally proceed
249+
* with the transition by calling `$urlRouter.sync()`.
247250
*
248251
* @example
249252
* <pre>
250-
* var app = angular.module('app', ['ui.router.router']);
251-
*
252-
* app.run(function ($urlRouter) {
253-
* $urlRouter.sync();
253+
* angular.module('app', ['ui.router']);
254+
* .run(function($rootScope, $urlRouter) {
255+
* $rootScope.$on('$locationChangeSuccess', function(evt) {
256+
* // Halt state change from even starting
257+
* evt.preventDefault();
258+
* // Perform custom logic
259+
* var meetsRequirement = ...
260+
* // Continue with the update and state transition if logic allows
261+
* if (meetsRequirement) $urlRouter.sync();
262+
* });
254263
* });
255264
* </pre>
256265
*/

0 commit comments

Comments
 (0)