@FNY3PM

Как грамотно сделать layout?

Есть Agular-модуль. У него есть ModuleLayoutComponent, который содержит базовую верстку, а так же для вывода компонентов. Вопрос: как можно немного менять ModuleLayoutComponen, чтобы в зависимости от текущего URL, показывались некоторые элементы?

Код модуля
@NgModule({
  declarations: [ModuleLayoutComponent],
  imports: [
    CommonModule,
    RouterModule.forChild([{path: '', pathMatch: 'full', component: ModuleLayoutComponent, children: [
      {path: '/order', component: OrderComponent},
      {path: '/payment', component: PaymentComponent}
    ]}])
  ],

})


ModuleLayoutComponent
<header></header>
<div class="content">
    <router-outlet></router-outlet>
</div>
<footer></footer>


Как сделать, чтобы если в router-outlet показывается PaymentComponent, то в родительском ModuleLayoutComponent добавить в футер кнопку назад?
  • Вопрос задан
  • 69 просмотров
Пригласить эксперта
Ответы на вопрос 1
@Ghoulll
Например вот так:
constructor(private router: Router) { }    
      this.router.events
      .subscribe( res => {
      if (res instanceof NavigationEnd) {
        this.currentUrl = res.urlAfterRedirects;
      }
    });

<ng-container *ngIf=currentUrl === 'какой-то url'
   <button>Назад</button>
</ng-container>
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы