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

Router Service transitionTo breaks with Query Params on nested transition #17494

Open
jtescher opened this issue Jan 20, 2019 · 17 comments
Open

Comments

@jtescher
Copy link

Calling transitionTo on a service in the context of an existing transition causes an assertion error to be thrown.

Example Twiddle here

Minimal logic from the reproduction above is: index route's beforeModel calls the auth service's ensureSignedIn method which uses the router's transitionTo method and includes a query param.

Calling it results in:

Assertion Failed: You passed the `login:security_key` query parameter during a transition into login, please update to security_key
@mabab
Copy link

mabab commented Jan 22, 2019

I have a similar error when trying to make transitionTo() into model(){}

this.get('router').transitionTo('tutor', tutorId, {queryParams: {anchor: 'user-balance'}});
Assertion Failed: You passed the tutor.index:anchor query parameter during a transition into tutor.index, please update to anchor

@miguelcobain
Copy link
Contributor

miguelcobain commented Jan 25, 2019

I'm also seeing the problem.

  • I have a reports and a reports.report child route
  • reports.report controller has queryParams: ['startDate', 'endDate']
  • reports route's setupController calls:
this.get('router').transitionTo('reports.report', report_id, {
  queryParams: {
    startDate: startDate.format('DD-MM-YYYY'),
    endDate: endDate.format('DD-MM-YYYY')
  }
});
  • results in the error on ember inspector's promises tab:
Error: Assertion Failed: You passed the `undefined:startDate` query parameter during a transition into reports.report, please update to startDate

I was able to track the problem up to this point:

screen shot 2019-01-25 at 17 28 57

Was able to reproduce this on ember 3.3.2, 3.4.8, 3.5.1, 3.6.1 and 3.7.
It was working with 2.18.2.

Weird thing is that it works with the router's this.transitionTo. Just doesn't work with the router service.

@ursqontis
Copy link

This is still an issue with Ember 3.8.2

@jordpo
Copy link

jordpo commented May 3, 2019

I ran into this issue as well - good to know that it is scoped just to the router service.

@IBue
Copy link

IBue commented Oct 22, 2019

ember-source 3.8.1 + ember-simple-auth >= 1.9.0

Problem occurs with an unauthenticated redirect (AuthenticatedRouteMixin#triggerAuthentication()) into a query-parameterized route.

ember-source 3.12.0 throws an error as in #14875 (comment)
but seemingliy whithout affecting application functionality

@kategengler
Copy link
Member

Hit this today, ember-source 3.13.4

@rwjblue
Copy link
Member

rwjblue commented Nov 19, 2019

I was thinking that this is fixed in 3.14 by #18244, anyone have a minute to try to confirm / deny?

@kbiedrzycki
Copy link

kbiedrzycki commented Dec 3, 2019

We were able to temporarily fix this using RouterService#urlFor method:

Controller.extend({
  router: service(),

  actions: {
    moveUser() {
      // before:
      this.get('router').transitionTo(routeName, routeParamOne, routeParamTwo);

      // after:
      this.customTransition(routeName, routeParamOne, routeParamTwo);
    }
  },

  customTransition(...params) {
    const url = this.get('router').urlFor(...params); // build url first

    this.get('router').transitionTo(url); // and make transition

    // And if you need to preserve query params, I guess you can use `window.location.search` and add this to url like:
    this.get('router').transitionTo(url + window.location.search);
  }
})

@michelvermeer
Copy link

We were able to temporarily fix this using RouterService#urlFor method:

Controller.extend({
  router: service(),

  actions: {
    moveUser() {
      // before:
      this.get('router').transitionTo(routeName, routeParamOne, routeParamTwo);

      // after:
      this.customTransition(routeName, routeParamOne, routeParamTwo);
    }
  },

  customTransition(...params) {
    const url = this.get('router').urlFor(...params); // build url first

    this.get('router').transitionTo(url); // and make transition

    // And if you need to preserve query params, I guess you can use `window.location.search` and add this to url like:
    this.get('router').transitionTo(url + window.location.search);
  }
})

Feels like a hack, but works like a charm. Good enough for me until version update

@bendemboski
Copy link
Contributor

In case it's helpful, here's a really minimal repro in a twiddle.

@Jbcampbe
Copy link

I am seeing this issue in [email protected]

@linearza
Copy link

Ran into this just now as well. Have seen it intermittently previously. The ESA link seems likely

@sly7-7
Copy link
Contributor

sly7-7 commented Mar 6, 2021

Hi all, I've taken @bendemboski twiddle, and created a repository to see what happen against 3.25.1. Unless I'm missing something it seems like this issue is resolved.

Screenshot from 2021-03-06 10-02-44

This would be great if someone could double check. https://github.com/sly7-7/repro-ember-17494

@jtescher Obviously, if you had a chance to update your app and see how it goes, it would be an super feedback :)
I've also reported your original twiddle here: https://github.com/sly7-7/repro-ember-17494/tree/from-original-twiddle
Screenshot from 2021-03-06 10-28-52

cc/ @rwjblue

@NLaza
Copy link

NLaza commented May 12, 2022

The bug is still present in ember version 3.28 and 4.3.

When I use the transitionTo from the router service to nested routes, it still updates the parent for the destination route. For example, if I transition from the current parent/child-a route by triggering this.router.transitionTo('parent.child-b'), the parent route's model hook will continue to be executed regardless of whether the transition is between child routes. This happens only if the parent route has query parameters.

The workaround from @kbiedrzycki (#17494 (comment)) still works on version 3.28 and 4.3.

@RobbieTheWagner
Copy link
Member

We're hitting an issue, which I think may be related to this bug. Query params always show up on the child route, even though we are not setting values for them, so the defaults should be hidden.

@kategengler
Copy link
Member

@RobbieTheWagner Have you seen #19492 and #19493 ?

@RobbieTheWagner
Copy link
Member

Thanks @kategengler!

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

No branches or pull requests