@@ -35,6 +35,10 @@ function stateContext(el) {
3535 * to the state that the link lives in, in other words the state that loaded the
3636 * template containing the link.
3737 *
38+ * You can specify options to pass to {@link ui.router.state.$state#go $state.go()}
39+ * using the `ui-sref-opts` attribute. Options are restricted to `location`, `inherit`,
40+ * and `reload`.
41+ *
3842 * @example
3943 * <pre>
4044 * <a ui-sref="home">Home</a> | <a ui-sref="about">About</a>
@@ -44,12 +48,17 @@ function stateContext(el) {
4448 * <a ui-sref="contacts.detail({ id: contact.id })">{{ contact.name }}</a>
4549 * </li>
4650 * </ul>
51+ *
52+ * <a ui-sref="home" ui-sref-opts="{reload: true}">Home</a>
4753 * </pre>
4854 *
4955 * @param {string } ui-sref 'stateName' can be any valid absolute or relative state
56+ * @param {Object } ui-sref-opts options to pass to {@link ui.router.state.$state#go $state.go()}
5057 */
5158$StateRefDirective . $inject = [ '$state' , '$timeout' ] ;
5259function $StateRefDirective ( $state , $timeout ) {
60+ var allowedOptions = [ 'location' , 'inherit' , 'reload' ] ;
61+
5362 return {
5463 restrict : 'A' ,
5564 require : '?^uiSrefActive' ,
@@ -59,11 +68,21 @@ function $StateRefDirective($state, $timeout) {
5968 var isForm = element [ 0 ] . nodeName === "FORM" ;
6069 var attr = isForm ? "action" : "href" , nav = true ;
6170
71+ var options = {
72+ relative : base
73+ } ;
74+ var optionsOverride = scope . $eval ( attrs . uiSrefOpts ) || { } ;
75+ angular . forEach ( allowedOptions , function ( option ) {
76+ if ( option in optionsOverride ) {
77+ options [ option ] = optionsOverride [ option ] ;
78+ }
79+ } ) ;
80+
6281 var update = function ( newVal ) {
6382 if ( newVal ) params = newVal ;
6483 if ( ! nav ) return ;
6584
66- var newHref = $state . href ( ref . state , params , { relative : base } ) ;
85+ var newHref = $state . href ( ref . state , params , options ) ;
6786
6887 if ( uiSrefActive ) {
6988 uiSrefActive . $$setStateInfo ( ref . state , params ) ;
@@ -90,7 +109,7 @@ function $StateRefDirective($state, $timeout) {
90109 if ( ! ( button > 1 || e . ctrlKey || e . metaKey || e . shiftKey || element . attr ( 'target' ) ) ) {
91110 // HACK: This is to allow ng-clicks to be processed before the transition is initiated:
92111 $timeout ( function ( ) {
93- $state . go ( ref . state , params , { relative : base } ) ;
112+ $state . go ( ref . state , params , options ) ;
94113 } ) ;
95114 e . preventDefault ( ) ;
96115 }
0 commit comments