我在我的Angular应用程序中添加了其他模态,它们都有不同的功能。
<router-outlet></router-outlet>
前一个工作正常,但添加第二个模态不同的路线后,第一个停止工作。name
如果我把另一个注释掉,一次只有一个在工作。
<button type="button" data-target="#settings2" data-toggle="modal" routerLink="setup_season">
Season
</button>
<button type="button" data-target="#settings" data-toggle="modal" routerLink="setup_package">
Package
</button>
第一个模态
<div id="settings" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal -->
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Modal Header</h4>
</div>
<div class="modal-body">
<router-outlet></router-outlet> // already tried with name attribute
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
第二模态
<div id="settings2" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal -->
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Modal Header</h4>
</div>
<div class="modal-body">
<router-outlet></router-outlet> // already tried with name attribute
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
你需要使用辅助路由,我贴一个类似案例的自己的代码,试着用你的代码做一下。
<div class="side-panel">
<!-- the auxiliary outlet -->
<router-outlet name="sidePanel"></router-outlet>
</div>
<div class="main-content m-0 p-0">
<!-- the primary outlet -->
<router-outlet></router-outlet>
</div>
路径的配置应该和这个类似。
const routes: Routes = [
{
path: '',
redirectTo: '/app/auth/login',
pathMatch: 'full'
},
{
path: 'app',
children: [
{
path: 'main',
component: MainComponent
},
{
path: 'side-menu',
component: SlidePanelComponent,
outlet: 'sidePanel', // You need to mention the name of the auxiliary route
}
]
]
最后,你需要在routerLink中提到出口的名称,就像这样:
<a [routerLink]="[{ outlets: { sidePanel: 'side-menu'}}]">