我有一个简单的有角度的[[(8 +)应用程序,使用@angular/router
并将多个组件作为路线,每个组件都使用@angular/animations
进行过渡。
<router-outlet>
指令是全屏显示,使用CSS width: 100vw
和height: 100vh
覆盖默认滚动。我的想法是用<div>
或允许定义固定布局的特定类包装每条路线。我当前的版本效果很好,
但是我必须手动添加<div>
并希望找到一种自动解决方案像@angular/animations
一样。
<main [@routerTransition]="getState(o)">
<router-outlet #o="outlet"></router-outlet>
</main>
路由组件html模板
<div class="route"> <!-- 👈 class which should be automatically wrapped -->
<div class="container">
<h1>title</h1>
<p>Blablabla</p>
</div>
</div>
路线
// State is use to bind animation
export const appRoutes: Routes = [
{
path: 'page1',
loadChildren: () => import('./page1/page1.module').then(mod => mod.Page1Module),
data: { theme: 'light' }
},
{
path: 'page2',
loadChildren: () => import('./page2/page2.module').then(mod => mod.Page2Module),
data: { theme: 'light' }
},
...
];
就像我说的那样,此代码有效
RouteShellComponent:
<div class="route">
<ng-content></ng-content>
</div>
RouteAComponent:
<div class="container"> <h1>title</h1> <div>...</div> </div>
主要
<app-route-shell> <router-outlet></router-outlet> </app-route-shell>