Oleg Oleg - 1 year ago 128
AngularJS Question

Change a url parameter in the current state from ui-sref in angular-ui-router

Using ui-router I would like to set a URL parameter no matter what state I'm in. A use-case for this is to switch between bookmarkable interface modes (e.g. "boring" or "funny").

I know it can be done using

directive, but in this case I'm left with href-less anchors, which is not very useful.

I have tried the most obvious
but it fails with "No reference point given for path '.'"

Does ui-router have a native solution to do this? Ideally I would like to have something like:

<a ui-sref="currentState({interface:'boring'})">boring</a>
<a ui-sref="currentState({interface:'fun'})">fun</a>

Answer Source

It seems that this functionality is available in the yet unreleased master branch of ui-router:

<a ui-sref="{foo:'bar'}">foobar</a>

See the related issue: https://github.com/angular-ui/ui-router/issues/1031