Ember.js: replaceWith() loses query-params

Created on 1 Sep 2014  Â·  11Comments  Â·  Source: emberjs/ember.js

Seems like replaceWith() don't respect query-params. When redirecting from one subroute to another using replaceWith() query-params of a parent route gets lost.

JSBin: http://jsbin.com/kinov/4
Example
Here is minimal code to reproduce:

App = Ember.Application.create()

App.Router.map ->
  @resource "lesson", ->
    @resource "slide"

App.LessonIndexRoute = Ember.Route.extend
  redirect: ->
    @replaceWith 'slide'

App.LessonController = Ember.Controller.extend
  queryParams: [ 'course' ]

index.hbs:

   {{#link-to 'lesson' (query-params course="bla-bla")}}
     lesson
   {{/link-to}}

slide.hbs

   <b>Slide template rendered. Attention to the URL.</b>
Bug Inactive Needs Submitter Response Query Params

Most helpful comment

Feature still needed and this is still happening in Ember : 2.4.6

All 11 comments

this.replaceWith '/url?param=value' preserves query parameters and can be used as workaround
http://jsbin.com/jixefu/2/edit

@machty is this a bug?

@machty ping.

I see the very same behaviour with this.redirectTo in 1.11.1.

I am also seeing this in 1.11.x

Feature still needed and this is still happening in Ember : 2.4.6

replaceWith does seem to honor the same, final "options" object as transitionTo. Ember/CLI 2.x workaround:

beforeModel(transition) {
  let { queryParams } = transition;
  this.replaceWith('your-next-route', { queryParams });
},

(Maybe you could just pass the transition directly. I worry that being interpreted as a model rather than an "options" object. And this is more explicit what problem you're working around.)

@H1D @bladnman @seawatts @john-kurkowski is this still an issue, perhaps we should close or create a new reproduction of this, what do you think?

@pixelhandler seems like this is not an issue anymore – https://ember-twiddle.com/2c2b711d799e789ad7043eaf94924108


But I've noticed something else

  • when "lesson" link clicked for the first time route lesson.slide became active due to redirect() in lesson route
  • if link clicked again route 'lesson' became active. Seems like redirect() wasn't called

Is this a correct routing behaviour?

@H1D I'll close this issue for now, perhaps reach out on the Ember Discord help channel to discuss further.

I'm having a similar issue. Unless a queryParam is defined on the destination controller, it is currently removed by replaceWith. Unsure if it's expected behaviour or not.

In the example below (full ember-twiddle here), landing on the redirect route, takes you to the destination route, but only keeps the query param that is defined on destination controller (utm_medium), and removes the other (utm_source):

// routes/redirect-page.js 
export default Ember.Route.extend({
  beforeModel(transition) {
    this.replaceWith('/destination?utm_medium=email&utm_source=newsletter')
  }
});

// controller/destination.js 
export default Ember.Controller.extend({
  queryParams: [ 'utm_medium' ], // omit utm_source on purpose
});

// Final url: 
// /destination?utm_medium=email
Was this page helpful?
0 / 5 - 0 ratings