2016-06-15 9 views
1

viewPortsを同じコンポーネントで使用することは可能ですか?2回インスタンス化されません。例えば。aurelia複数のビュー同じコンポーネントのポップアップ

config.map([ 
     { 
      route: 'route1', 
      name: 'route1', 
      viewPorts: { 
       default: {moduleId: './route1-module'}, 
       heading: {moduleId: './route1-module', view: './route1-module-heading.html'} 
      }, 
      nav: true, 
      title: 'Route1' 

     }]); 

route1のモジュールインスタンス化され、二回添付されています。私はそれを避ける必要があります。

+0

(それはまた、あなたがあまりにもビューポートのレイアウトを指定することができるという点で、ビューポートで動作します)ビューポートから非常に異なるのか? 2つのビューポートがあります... 2つのビューポートで同じコンポーネントをどのように共有しますか?同じバッキングVMと同じビューが必要ですか? – Charleh

+0

2つのビューを持つ1つのバッキングコンポーネントが必要です。親ビューで異なる部分にアタッチすることができます。 –

+0

基本的に2ビットのコンテンツがレンダリングされるプレースホルダが必要ですが、1つのビューモデルでそれを元に戻す必要がありますか? MVCの部分ページやASP.NETマスターページのようなもの? – Charleh

答えて

3

最新のリリースで提供されるレイアウト機能を使用したいと思うようです(私は最近、PRが最近マージされた時期はわかりません)。

PRはここにある:https://github.com/aurelia/templating-router/pull/25

は、基本的にそれはあなたにルーティングする場合、元のモジュールの代わりに座って眺め/のviewmodelペア(レイアウト)を指定する機会を与えてくれます。代わりに、元のコンテンツはslotsを使用してレイアウトに投影されます。

例:

ルート設定

config.map([ 
    { layoutView: "layout.html", moduleId: 'page1' } 
]); 

page1.html

<template> 
    <div slot="slot1">some content</div> 
    <div slot="slot2">some other content</div> 
</template> 

layout.html

<template> 
    <div class="some-fancy-container"> 
     <p>This is slot 2</p> 
     <!-- slot2 content will be projected here --> 
     <slot name="slot2">some fallback content</slot> 
    </div> 
    <div class="sidebar"> 
     <p>This is slot 1</p> 
     <!-- slot1 content will be projected here --> 
     <slot name="slot1">some fallback content</slot> 
    </div> 
</template> 

結果のHTML出力:

<template> 
    <div class="some-fancy-container"> 
     <p>This is slot 2</p> 
     some other content 
    </div> 
    <div class="sidebar"> 
     <p>This is slot 1</p> 
     some content 
    </div> 
</template> 

これはMVCのパーシャルやASP.NETマスターページに似ており、あなたが(子ルートを必要とせずに)特定のページのための代替レイアウトを指定することができます。

それはあなたがそれを行うには期待している何

関連する問題