Mapping queryParams -- proposal or request for best practice


#1

I have a route which takes a query parameter info=<type>:<id>. The page generated needs to display an info box about a sub-item of the current item (of which 6 types are possible). In order to do this, currently, I need to resolve all the asynchronous bits for the sub-item in the route for the parent object, then use a named outlet and controller for the sub-item.

This is unfortunate as it means the parent route is coupled with all the sub-items in order to load everything needed for a displayed sub-item in afterModel.

What I think I’d like to do is to have sub-routes for the individual routes mapped to values of the query parameters. I would envision something like:

this.resource( 'parent', {...}, function() {
    this.route( 'type1', { queryParams: { info: /type1:.\d+/ } } );
    ...
});

Here the first matching regex for (all) the query parameter(s) causes the sub-route to be selected.

If there is an alternative best practice for my situation, I would be eager to hear it. Note that, in my case, the parent object can have other sub-routes that co-exist with the presence of info, so converting info into part of the url stem would just cause my coupling problem to multiply.

Thanks!

[PS – the presence of other subroutes together with QP-mapped routes brings up the problem of nesting order. I would think the best way to do this is to serialize all stem-matching routes, then add QP-mapped routes as subroutes.]


Promises and computed properties