Answer the question
In order to leave comments, you need to log in
How to change two components depending on route in Angular 2+?
Is there an application like this?
<root-component>
<div id="header>
<header-component>
Здесь верхнее меню и некоторые блоки (например - касса итд).
Зависит от маршрута
Часто этот компонент может соответствовать нескольким маршрутам
</header-component>
<right-menu-component>
Меню в верхнем левом углу. Не зависит от маршрута, всегда показывается.
</right-menu-component>
</div>
<div id="content">
<router-outlet>
//Здесь всё содержимое, вся бизнес-логика. Зависит от маршрута.
</router-outlet>
</div>
</root-component>
const routes: Routes = [
{ path: 'orders', components:
[
{selector: 'header-component', component: 'SomeHeader'},
{selector: 'content-component', component: 'SomeComponent'}
]
}...
Answer the question
In order to leave comments, you need to log in
If you understand correctly, then you can, for example, create a layout module in shared, in which there will be a wrapper directory (wrappers) and all other parts of the frame (header, sidebar, footer, etc.). And now the assembled frames for certain routes will be located in the wrapper. For example, there will be FirstLayoutComponent and SecondLayoutComponent. With frameworks like:
<header>...</header>
<main>
<router-outlet></main>
<footer>...</footer>
<header>...</header>
<main>
<sidebar>...</sidebar>
<router-outlet>
</main>
<footer>...</footer>
const routes: Routes = [
{
path: 'first', component: FirstLayoutComponent, children: [
{ path: 'test1', component: Test1Component }
]
},
{
path: 'secod'm component: SecondLayoutComponent, children: [
{ path: 'test2', component: Test2Component }
]
}
];
Put them both in the parent. and on the route of the parent's owl.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question