Skip to content

updating url only without any other actions #3122

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
mackelito opened this issue Nov 1, 2016 · 10 comments
Closed

updating url only without any other actions #3122

mackelito opened this issue Nov 1, 2016 · 10 comments
Labels

Comments

@mackelito
Copy link

mackelito commented Nov 1, 2016

I have a component with 200+ items and want to update the url to be something like 'category/3#24-MB01' when scrolling.

When a item comes in view I update the url using this code:

$state.go($state.current.name, param, {
    notify: false,
    reload: false,
    location: 'replace'
});

Url is updated but the browser navigates to the item with id "#24-MB01"...

Have been searching both StackOverflow and the issues and now I´m kind of lost.. Any guidance is much appreciated!

Note: Using 1.0 beta3

@mackelito
Copy link
Author

Looks like I found the solution after all.. setting dynamic: true on the param seems to work..

@mackelito
Copy link
Author

mackelito commented Nov 1, 2016

I spoke to soon... still having this problem..

Note: The issue seems to be that I use "#".. changing to "id" stops the wired issue, testing some more..

Note2: For now I have a hack to get me moving.

$location.hash(this.$stateParams.id);

it works but the url´s look like crap! ("category/3?id=24-WB06#24-WB06")

so it would still be nice to get some ideas on this issue :)

@mackelito mackelito reopened this Nov 1, 2016
@christopherthielen
Copy link
Contributor

I'm assuming you're using some sort of scroll spy. The router manages the URL hash as a state parameter. You should be able to update it by changing the parameter # to whatever you want it to be.

$state.go(".", { #: '24-WB06'}, { location: 'replace' });

@mackelito
Copy link
Author

Yes I have a scroll spy (using https://github.com/camwiegert/in-view) thx to your reply I figured out how to get it working better but still not flawless ;)

the problem right now is that when I update url it jumps to top if that item creating a sort of page flickering.. but this is just a matter of implementation pattern..

Thx for you help and keep up the awesome work on the module! it´s truly a gem!

@mackelito
Copy link
Author

mackelito commented Nov 10, 2016

Spoke to soon.. again... so the .go will trigger a transition but I just want to update the location.. how?

@mackelito mackelito reopened this Nov 10, 2016
@christopherthielen
Copy link
Contributor

$state.go(".", { #: '24-WB06'}, { location: 'replace' }); triggers a transition, yes, but the transition is dynamic, and all it does is update the URL.

@mackelito
Copy link
Author

And also triggers the view to scroll to the id!(?)

On 11 Nov 2016, at 18:43, Chris Thielen [email protected] wrote:

$state.go(".", { #: '24-WB06'}, { location: 'replace' }); triggers a transition, yes, but the transition is dynamic, and all it does is update the URL.


You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub, or mute the thread.

@christopherthielen
Copy link
Contributor

@mackelito that's native browser behavior, right? How does other scrollspy implementations update the browser hash without triggering scrolling?

@mackelito
Copy link
Author

I guess it should prevent the "bubble" event.. perhaps by using stopPropagation?

@christopherthielen
Copy link
Contributor

I think that's your homework :) Figure out how other scrollspy implementations do it (then do that).

If you find that you can't implement it without some specific support from ui-router, feel free to re-open this issue and we can discuss the ramifications. Otherwise, I'm closing because I think ui-router is doing what it should be doing.

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

No branches or pull requests

2 participants