How to access query parameters from route in Ember 1.7

后端 未结 5 455
傲寒
傲寒 2020-12-16 12:08

In 1.7 Ember should support Query Parameters. I have no problems using them in controller but I\'d like to access them in Route, ideally in beforeModel hook but model hook w

5条回答
  •  自闭症患者
    2020-12-16 12:22

    In the latest version of ember (2.12 at the time of writing this answer), queryParams can be accessed in the model hook as follows:

    import Ember from 'ember';
    
    export default Ember.Route.extend({
        queryParams: {
            test: ''
        },
        model(params) {
            console.log(params.test);
        },
    });
    

    Observe that now both dynamic segment and queryParams are accessible via the params object. Since params is not available in the beforeModel hook, this solution works on when you have to access the queryParams in the model hook.

提交回复
热议问题