Skip to content
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

Fix queryParamsOnly being correct on transitions. #198

Merged

Conversation

alexspeller
Copy link
Contributor

This property has been set incorrectly on some transitions, notably when the
transition is caused by the Router#refresh() method in queryParamsDidChange.

This is the method ember uses to implement refreshModel option of query params,
so fixing this bug allows refreshModel to be used in conjunction with
replace option for query params, currently it is either-or.

Resolves emberjs/ember.js#10577 and emberjs/ember.js#11843

@alexspeller
Copy link
Contributor Author

@mike-north this is relevant to your interests.

@rwjblue
Copy link
Collaborator

rwjblue commented Oct 30, 2016

This looks good to me, thanks for tackling it!

I'll leave it open for a day or so and give others a chance to review too...

This property has been set incorrectly on some transitions, notably when the
transition is caused by the Router#refresh() method in queryParamsDidChange.

This is the method ember uses to implement `refreshModel` option of query params,
so fixing this bug allows `refreshModel` to be used in conjunction with
`replace` option for query params, currently it is either-or.
@alexspeller alexspeller force-pushed the fix-queryParamsOnly-property-on-transition branch from 437fd1a to 9e5440b Compare October 31, 2016 23:16
@nathanhammond
Copy link
Contributor

@rwjblue I'm still 👍 on this.

@darylalexjohnson
Copy link

@nathanhammond good news! Thanks

@engwan
Copy link

engwan commented Dec 21, 2016

+1 Any update on this?

alexspeller referenced this pull request Jan 13, 2017
This has been broken forever AFAIK, and is surprising to a lot of people. In
fact, even the ember guides recommend [using `this.transitionTo` for redirecting](https://guides.emberjs.com/v2.9.0/routing/redirection/)

This is in fact broken. If you use `transitionTo` as a redirect strategy,
then you get an extra history entry if you hit the route as the first route in
your app. This breaks the back button, as the back button takes you to the route
with the redirect, then immediately redirects back to the page you're on.
Maybe you can go back if you hammer back button really quickly, but you have to
hammer it loads super quick. Not a good UX.

`replaceWith` works if you use it to redirect from a route that's your
initial transition. However if you use it to redirect and you hit that route
from some way _after_ the initial app load, then at the point that the
replaceWith is called, you are still on the same URL. For example, if you are on
`/` and you click a link to `/foo`, which in it's model hook redirects to `/bar`
using `replaceWith`, at the time replaceWith is called, your current url is `/`.

This means `/` entry gets removed from your history entirely. Clicking back
will take you back to whatever page you were on before `/`, which often isn't
event your app, maybe it's google or something. This breaks the back button
again.

This commit should do the correct thing in all cases, allowing replaceWith and
transitionTo outside of redirects as specified by the developer but only allowing
transitionTo or replaceWith in redirects in a way that doesn't break the back
button.
@rwjblue rwjblue merged commit b4419b7 into tildeio:master Jan 17, 2017
alexspeller added a commit to alexspeller/router.js that referenced this pull request Apr 17, 2017
So I fixed this in tildeio#198. But it was broken again by tildeio#197 and the tests didn't
catch that. So I've improved the tests and fixed it 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.

Query Params replace doesn't work if refreshModel is also used
5 participants