【发布时间】:2019-06-28 07:46:33
【问题描述】:
我正在使用 Angular Flex 布局的 Angular 7 项目。在桌面视图上,我在移动设备上有一个标签导航和一个 sidenav。我使用 fxHide 和 fxShow 来显示正确的导航。但是只要有两个路由器插座,我的路由就会被破坏,无论是在桌面还是移动设备上。如果路由在桌面上不起作用,我必须评论移动出口,反之亦然。
fxHide设置显示为none,为什么隐藏的outlet有效果?
我不能使用命名的网点,因为我的导航共享相同的路线,而且它弄乱了网址。
我在 Stackblitz 中重现了我的问题: https://stackblitz.com/edit/angular-kaejkr?embed=1&file=src/app/app.component.html&view=preview
app.component.html
<a fxHide fxShow.gt-xs="true" routerLink="hello">desktop-nav</a>
<a fxShow fxHide.gt-xs="true" routerLink="hello">mobile-nav</a>
<div class="desktop" fxHide fxShow.gt-xs="true">
<router-outlet></router-outlet>
</div>
<div class="mobile" fxShow fxHide.gt-xs="true">
<router-outlet></router-outlet>
</div>
app.routing.ts
const routes: Routes = [
{ path: "", redirectTo: "hello", pathMatch: "full" },
{ path: "hello", component: HelloComponent }
];
【问题讨论】:
-
为什么需要两个路由器插座?如果您能解释这一点,我会尽力提供帮助。另外,请注意,您的 stackblitz 与您在此处粘贴的代码不同...您能否更新一下,使它们保持一致。
标签: angular routing angular-flex-layout router-outlet