ember.js icon indicating copy to clipboard operation
ember.js copied to clipboard

Router Service transitionTo breaks with Query Params on nested transition

Open jtescher opened this issue 6 years ago • 14 comments

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

jtescher avatar Jan 20 '19 05:01 jtescher

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

mabab avatar Jan 22 '19 14:01 mabab

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.

miguelcobain avatar Jan 25 '19 17:01 miguelcobain

This is still an issue with Ember 3.8.2

ursqontis avatar Apr 18 '19 11:04 ursqontis

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

jordpo avatar May 03 '19 13:05 jordpo

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 https://github.com/emberjs/ember.js/issues/14875#issuecomment-283152339 but seemingliy whithout affecting application functionality

IBue avatar Oct 22 '19 08:10 IBue

Hit this today, ember-source 3.13.4

kategengler avatar Nov 16 '19 00:11 kategengler

I was thinking that this is fixed in 3.14 by https://github.com/emberjs/ember.js/pull/18244, anyone have a minute to try to confirm / deny?

rwjblue avatar Nov 19 '19 03:11 rwjblue

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);
  }
})

kbiedrzycki avatar Dec 03 '19 20:12 kbiedrzycki

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

michelvermeer avatar Feb 26 '20 22:02 michelvermeer

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

bendemboski avatar May 08 '20 21:05 bendemboski

I am seeing this issue in [email protected]

Jbcampbe avatar Sep 22 '20 23:09 Jbcampbe

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

linearza avatar Nov 17 '20 16:11 linearza

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

sly7-7 avatar Mar 06 '21 09:03 sly7-7

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 (https://github.com/emberjs/ember.js/issues/17494#issuecomment-561341173) still works on version 3.28 and 4.3.

NLaza avatar May 12 '22 07:05 NLaza

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.

RobbieTheWagner avatar Mar 01 '23 16:03 RobbieTheWagner

@RobbieTheWagner Have you seen https://github.com/emberjs/ember.js/issues/19492 and https://github.com/emberjs/ember.js/issues/19493 ?

kategengler avatar Mar 01 '23 17:03 kategengler

Thanks @kategengler!

RobbieTheWagner avatar Mar 01 '23 17:03 RobbieTheWagner