mercredi 1 novembre 2017

Reformating query parameters in the route

I have a controller query parameter:

export default Controller.extend({
    myParam: undefined,
    queryParams: ['myParam'],
});

that I want to refresh the model with:

export default Route.extend({
    queryParams: {
        myParam: {
            refreshModel: true
        }
    }
});

This correctly formats and tracks the variable in my app's URL (in other words the browser URL):

myapp.com?myParam=1

and correctly sends the corresponding request to my API:

[GET] myapi.com?myParam=1

I want to remap the query parameter so that I can continue to use the myParam variable in my controller, but the request to my API gets mapped to:

[GET] myapi.com?my_param=1

I've tried the following on my controller:

export default Controller.extend({
    queryParams: {
        myParam: 'my_param'
    },
});

and this makes the URL in my application (the browser URL) correctly change to my_param when I change the variable:

myapp.com?my_param=1

but it doesn't change the parameter that is sent to my API, which remains:

[GET] myapi.com?myParam=1

Is there away to map the variable that is refreshing the model in my route to a different URl param?




Aucun commentaire:

Enregistrer un commentaire