Link-to helper to reset query param(s) to null?


#1

I’ve ran into an issue with link-to helper and a route which has optional query params.

I have a ‘projects’ route which lists all Projects, but the related view also offers a list of links which filter the Projects out by their Category ('/projects?category=art'). So, default controller properties that link to query-params are all null. I’m having a hard time figuring out how to place a link-to helper in the same view which leads to a ‘clean’ route, without the query params. Placing a link-to helper with no query-params just leads to the current projects route, keeping any query params from the current URL - and what’s worse, keeps it marked as active.

Is there any way to force the link-to helper to ignore current URL query params?


#2

For something similar, I added a controller property such as

defaultCategory: null

and then in the link-to helper used

(query-params category=defaultCategory)

I’d love for a simpler way to reset a query param though.


#3

I’ve ran into a similar issue, I have a controller that supports quite a handful of query params and would like to have a link-to that reset all of the query parameters to their defaults.

Currently there doesn’t seem to be any way to do this without explicitly specifying each and every query param that you want to reset, and having a reference to what the default should be.

Am I missing something?


#4

They are on to something: http://emberjs.com/blog/2014/03/22/core-team-meeting-minutes-2014-03-07.html https://github.com/emberjs/ember.js/issues/5274


#5

Setting it to “null” (as a string) worked for me. Don’t remember how I landed on that one. Clearly not super intuitive.

     li
        = link-to "admin.classes" (query-params filter="archived")
          .fa.fa-check
          span Archived
      li.divider
      li
        = link-to "admin.classes" (query-params filter="null")
          .fa.fa-check
          span All