angularjs - UI Router mathing url with hash (fragment) -


using ui router need match urls hash (fragment) included in (html5 mode).

.state('mystate', {             url: '/path/:id/page#:section',             templateurl: 'template.html',             controller: 'mycontroller'         }); 

while setup above works when using ui-sref below..

<a ui-sref="mystate({id: 1})"> ... // without hash => section == '' <a ui-sref="mystate({id: 1, section: 'abc'})"> ... // section == 'abc' 

.. fails when redirect browser other page manually specifying fragment in address bar (or when link including hash clicked on totally different site) in case url matcher tries match against url without hash , forced create new artificial state same above without hash , param section in it's url property. leaves me without possibility have bookmarkable url hash included.

i need have 1 state, fragment param optional , correctly matched in-app state transition , url matching mechanism when redirected page preserving given section parameter (if present).

i resolved issue using # param instead:

<a ui-sref="mystate({id: 1})"> ... // without hash => # == '' <a ui-sref="mystate({id: 1, '#': 'abc'})"> ... // # == 'abc' 

and url in state definition without hash together:

url: '/path/:id/page', 

this matches state on page load hash in url, still doesn't set # value in state params. resolved manually setting param in $statechangestart event handler:

 $rootscope.$on('$statechangestart',       function(event, tostate, toparams, fromstate, fromparams) {             var hash = $location.hash();             if (hash) {                  toparams['#'] = hash;             }       } 

Comments

Popular posts from this blog

IF statement in MySQL trigger -

c++ - What does MSC in "// appease MSC" comments mean? -

javascript - Blogger related post gadget image Resize s72-c [ Need Expert Help ] -