2015-12-02 34 views
1

日安StackOverflow的工作,this.transitionToRoute不無PARAMS

// 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'); 

幫助,我想如果沒有選擇在視圖中的任何PARAMS去 '使用domain.tld/myresource'。但它不工作:(

回答

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'); 
0

你應該巢的路線是這樣的:

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

這應該給你,你不要求工作圍繞URL路徑,再加上清理你的路由/查看/控制器/組件名稱

+0

好的,應該如何查看資源控制器?我想爲/ myresource和/ myresource /使用一個控制器::param1 - 這是/ myresource的過濾器主控制器是資源不是資源 – iTux

+0

您可以在路由上設置controllerName屬性,但如果這只是過濾器,最好使用查詢參數而不是動態段。 – NicholasJohn16

+0

我知道,但我想要URL/myresource /過濾值,因爲這個URL比/ myresource乾淨嗎?param1 =值 – iTux