Skip to content

support setting url #fragments in state params #1187

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed

support setting url #fragments in state params #1187

wants to merge 1 commit into from

Conversation

mismith
Copy link

@mismith mismith commented Jul 4, 2014

As per @sadlerw's request in #701

NB: obviously HTML5 mode needs to be enabled for this to have any effect
Supports both formats:

  • ui-sref="mystate(myparams)#{{ myhashexpression }}"
  • ui-sref="mystate({myparam1: myvalue1, myparam2: myvalue2, '#': myhashexpression})"

@timkindberg
Copy link
Contributor

Hi @mismith thanks for contributing. Several things need to be fixed though, all of which are summarized here: https://github.com/angular-ui/ui-router#contribute

  1. Needs test coverage
  2. Needs proper commit message formatting
  3. You have jshint issues
Running "jshint:all" (jshint) task
Linting src/urlRouter.js ...ERROR
[L392:C1] W099: Mixed spaces and tabs.
        url += '#' + params['#'];
Linting build/angular-ui-router.js ...ERROR
[L1712:C1] W099: Mixed spaces and tabs.
        url += '#' + params['#'];
Warning: Task "jshint:all" failed.

@cedricziel
Copy link

@mismith any progress? If needed, i'd try to pr to your feature branch

@mismith
Copy link
Author

mismith commented Jul 29, 2014

Sorry guys, I just don't have time to do this properly right now, feel free to take what I have if you need it

@OnkelTem
Copy link

Murray, would you provide some example on how this is supposed to work?
Specifically, should location be rewritten after state transition to include #<fragment>? From what I tested this is not happening: ui-sref directive is now correctly creates URL with fragment, but when clicking on a link, no fragment is added to location.href

@mismith
Copy link
Author

mismith commented Apr 1, 2015

@OnkelTem: "should location be rewritten after state transition to include #". Yes.
Perhaps since I created this PR the master branch has changed in such a way that this no longer works—or maybe browsers have evolved themselves—but back then it did indeed add the #fragment to the URL after/on clicking the link.

@mismith
Copy link
Author

mismith commented Apr 1, 2015

Yes, it looks like the following line in the latest master branch is what's stripping out the # param:

toParams = toState.params.$$values(toParams);

Then, a little lower down, another line also filters out the # again:

toParams = filterByKeys(to.params.$$keys(), toParams || {});

Basically, by the time we get to building a URL in the parent $state.transitionTo method, we no longer have toParams['#'] set. Finally, when we internally call UrlMatcher.format() from within $urlRouter.push(), it also strips out the # again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants