如果没有参数,this.transitionToRoute不起作用

时间:2015-12-02 19:11:33

标签: javascript ember.js web-applications routes

美好的一天StackOverflow,

// routes
Router.map(function() {
    this.resource('myresource');
    this.resource('myresource', { path: 'myresource/:param1' });
});

// call transition from controller when switch not selected any params
// doesn't work...
this.transitionToRoute('myresource');

需要帮助,如果没有在视图中选择任何参数,我想去'domain.tld / myresource'。但这不起作用:(

2 个答案:

答案 0 :(得分:0)

// router
Router.map(function() {
    this.route('myresource');
    this.route('anothermyresource', { path: 'myresource/: param1' });   
});

// router extend for another my resource
setupController: function(controller, model) {
        this.controllerFor('myresource').setProperties({isNew:false, content:model});
    },
    renderTemplate: function() {
        this.render('myresource');         
    },
    model: function (params) {
        if (params.param1 === 'paramValue') return this.store.find('resource', {param1: 0});
    }

// and now work like as need
this.transitionToRoute('myresource'); 

答案 1 :(得分:0)

你应该像这样嵌套你的路线:

Router.map(function() {
    this.route('resources', {path: '/myresource', function() {
        this.route('resource', {path: '/myresource/:param1'});
    }); 
});

这应该为您提供您无需解决方案的请求的URL路由,并清理您的路由/视图/控制器/组件名称。