Migrating from router(-direct) to router(-lite): params / queryParams

Hi, preparing a migration plan, I found out there seem to be a significant difference in how extra params (queryParams) are handled. By extra params I mean the parameters that are not explicitly specified in the route definition.

  • In router-direct, all the params passed to the route, would end up in the “params” argument of canLoad: /list/:category + /list/root?sort=name -> params: {category: root, sort: name}
  • In router-lite, only the parameters that are explicitly defined in the route are passed: /list/:category + /list/root?sort=name -> params: {category: root}. The remaining are available via next.queryParams: {sort: name}

I understand this is by design as stated here by @Sayan751 and frankly it does make sense to me.

However, since this is a migration scenario (and now that router-lite became the default router it might be quite common soon) I am wondering whether it might be possible to override the behavior and pass the combined params + queryParams for the sake of compatibility with router(-direct)?
I tried the lifecycleHooks but it seems params is read-only there.

Hi @migajek, is it enough if the combined parameters are provided to the hook methods, such as canLoad or loading?

Hi @Sayan751, I believe it would be enough. Obtaining the current route need code changes anyway :slight_smile:

I just wonder whether that would be feasible to allow mutating in the hooks, that’d make it quite flexible :slight_smile:

I have opened the PR here: chore(router): added an option to treat query parameters as path parameters by Sayan751 · Pull Request #2209 · aurelia/aurelia · GitHub. Feel free to have a look.

I just wonder whether that would be feasible to allow mutating in the hooks, that’d make it quite flexible :slight_smile:

It is not. Both the configured parameters and the unconfigued query parameters come from either the browser URL or the routing instruction (whatever you are passing to the Router#load) and those are assumed readonly for obvious reason.

May I ask what use-case you want to address by changing the parameters from the hook?

1 Like

Sorry for the late reply, been on vacation :slight_smile:

The only reason I wanted to alter the parameters in the hook, was to pass the query params as params without the changes to aurelia router itself :slight_smile:

@migajek The said PR is merged. So feel free to try it out. The docs are her: Router configuration | The Aurelia 2 Docs.

In case there is any residual issues, please share a minimal reproduction, so that it is easier to understand the problem.

2 Likes