Skip to content

Keep (Parent Route) Query Parameters #476

@buschtoens

Description

@buschtoens

The default behavior of Ember's <LinkTo> is to keep the query parameters of parent routes.

<Link> does not auto-append any query parameters to the generated URL. They need to be passed in explicitly via @query. This is über annoying, when you want to use <Link> as a substitute for <LinkTo> in a scenario where a child route links back to a parent route.

<Link> and {{link}} should offer a @keepQuery option. It can take these values:

  • none / falsy value (default, current behavior): No QPs of the current location are kept.
    • Only QPs provided via @query are appended.
  • known: Only QPs of the current location at the time of invocation that are defined as known QPs in the current route hierarchy are kept.
    • QPs provided via @query override these QPs individually.
    • A null / undefiend value in the @query object will remove a kept QP.
  • all: All QPs of the current location at the time of invocation are kept.
    • QPs provided via @query override these QPs individually.
    • A null / undefiend value in the @query object will remove a kept QP.
  • tracked-known: Only QPs that are defined as known QPs in the current route hierarchy are kept.
    • When the the current route / QPs change, the url will be updated live.
    • QPs provided via @query override these QPs individually.
    • A null / undefiend value in the @query object will remove a kept QP.
  • tracked-all: All QPs of the current location are kept.
    • When the the current route / QPs change, the url will be updated live.
    • QPs provided via @query override these QPs individually.
    • A null / undefiend value in the @query object will remove a kept QP.

Unresolved Questions

none is the current behavior. Changing this would be a breaking change IMO, so I'd make it the default, too. Do we want to keep it this way though or switch to a different default?

Assuming we want to switch, we could raise a deprecation warning, prompting the user to explicitly chose none or a different behavior.
Should the default be configurable or should we allow users to opt-in to the new default mode prior to upgrading to the next major version?

Do the names used here make sense? @keepQuery, none, known, all, tracked-*, untracked-*?

Do we need the tracked-* variants? Or do we not need the untracked variant? Should the untracked variants also be prefixed with untracked-*? Or should the tracked-* variants instead have no prefix?

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions