2017-07-25 41 views
0

根据aurelia文档中给出的示例我打开对话框与viewmodel(说提示)。这个提示里面有我添加“router-view”标签的视图。Aurelia路由器视图内部对话框不工作在重新打开对话框

我的路线已配置好。所以当我第一次打开对话框时,它会打开路由中配置的正确视图,并且一切正常。但是,当我关闭对话框并重新打开对话框时,它不显示第一个路径视图。如果我点击其他路线链接并返回到第一条路线,它将起作用。

我观察到它没有创建第一个路径的视图模型的实例(当第二次打开对话框时)。 如何解决这个问题? 提示HTML

<template><div class="row"> 
    <left-menu ></left-menu> 
    <router-view></router-view> 
    </div></template> 
<template> 

和左menu.htm

<template> 
<div class="list-group"> 
    <template repeat.for="item of items"> 
     <a class="list-group-item ${$parent.selectedNav === item.routeName ? 'active' : ''}" route-href="route.bind: item.routeName;" click.delegate="$parent.select(item)">${item.text}</a> 
    </template>   
</div>  

+1

我同意以下4imble。路由器背后的用户体验思想是一个登录页面,您希望有人能够导航到和离开。模式背后的用户体验思想是页面中断,需要进行一些过程才能完成或继续页面上的逻辑。 您可能构建的是一个向导,一个多步模态对话框。为了达到这个目的,我鼓励使用''并管理这些步骤。 –

回答

1

使用模式窗口内的路由器似乎离我。路由器用于管理页面,但使用模式管理页面内的内容。

我会建议构建一个模式窗口组件,您可以使用<slot>标记来注入内容并将其模型绑定到当前视图模型中的任何数据。

下面是我为此使用的组件示例。

<template> 
    <div show.bind="visibility" class="modal-window"> 
    <div> 
     <button class="btn btn-danger btn-sm close-button" click.delegate="close()">close</button> 
    </div> 
    <slot></slot> 
    </div> 
    <div show.bind="visibility" class="modal-window-overlay" click.delegate="close()"></div> 
</template> 

-

import { bindable } from 'aurelia-framework'; 

export class ModalContent { 
    @bindable visibility: boolean; 

    close(){ 
     this.visibility = false; 
    } 
} 

<modal-content id.bind="'add-variant-window'"> 
     <h4>Modal Content</h4> 
     <div>you can bind this to things on the current viewmodel</div> 
</modal-content>