2013-09-30 47 views
1

我想創建一個可以通過自己的路線訪問的模態視圖。灰燼。使模態視圖具有其自己的路線

問題是 - 我想在我的應用程序的其他狀態/視圖/路線上顯示這個視圖,這些視圖裏面有大數據。

我以爲我可以做到嵌套路線。如果我們過渡到孩子的路線,沒有什麼會被重新計算,只是孩子表演 - 非常好。

但在實踐中,當我試圖爲我的某些資源添加子路由時。我遇到了this question中描述的問題。所以,嵌套路由不是解決方案。

什麼是解決方案?有任何想法嗎?

回答

0

我的解決方案就在這裏。 (事實是它與一些騙子嵌套路由)

1)語氣去「模式」出口

2)我們有不同的名字模式的路線,但具有相同的路徑部分。

this.resource('category', { path: '/category/:category_id' }, function() { 
    /* Different names for the same modal route */ 
    this.resource('modal1', { path: 'card/:card_id' }); 
}); 

// url - semantic/books/card/id99 
this.resource('semantic', { path: '/semantic/:semantic_id' }, function() { 
    /* Different names for the same modal route */ 
    this.resource('modal2', { path: 'card/:card_id' }); 
}); 

3)當執行transitionTo我們要通過上下文父路由

var curPath = this.controllerFor("application").currentPath; 

if (/^category/g.test(curPath)) 
    this.transitionToRoute('modal1', { category_id: cat_id, card_id: card_id) }); 
else if (/^semantic/g.test(curPath)) 
    this.transitionToRoute('modal2', { semantic_id: sem_id, card_id: card_id) });    
2

如果它必須在它自己的路線中,更合適的方法是將一條單獨的路線傳遞給「前一路線」上下文以避免路線序列化衝突。如果你打算沒有一條單獨的路線,你可以在一個新的出路中渲染一個'模態'視圖,並且不承擔將上下文'麪包屑'傳遞到模態路線的開銷。

+0

反正我有渲染模式,以新的出路。 我使它與你的建議類似,但有一點區別。看看我的答案。 – bug0r