$urlRouter
ui.router.router
A URL generation method that returns the compiled URL for a given
UrlMatcher
, populated with the provided parameters.
Param | Type | Details |
---|---|---|
urlMatcher | UrlMatcher | The |
params (optional) | object | An object of parameter values to fill the matcher's required parameters. |
options (optional) | object | Options object. The options are:
|
string | Returns the fully compiled URL, or |
$bob = $urlRouter.href(new UrlMatcher("/about/:person"), { person: "bob" }); // $bob == "/about/bob";
Triggers an update; the same update that happens when the address bar url changes, aka $locationChangeSuccess
.
This method is useful when you need to use preventDefault()
on the $locationChangeSuccess
event,
perform some custom logic (route protection, auth, config, redirection, etc) and then finally proceed
with the transition by calling $urlRouter.sync()
.
angular.module('app', ['ui.router']) .run(function($rootScope, $urlRouter) { $rootScope.$on('$locationChangeSuccess', function(evt) { // Halt state change from even starting evt.preventDefault(); // Perform custom logic var meetsRequirement = ... // Continue with the update and state transition if logic allows if (meetsRequirement) $urlRouter.sync(); }); });