Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 2 - Standalone Component (without layout)

Tags:

angular

Is it possible to create "standalone" components, meaning components without the basic app layout?

In my app.component.html I defined the navigation, header and footer. But now I want a login component that uses a different base layout.

My app.component.html looks like this:

<!-- Wrapper-->
<div id="wrapper">
    <!-- Left navigation bar -->
    <app-navigation></app-navigation>

    <!-- Main page wrapper -->
    <div id="page-wrapper" class="gray-bg">

        <!-- Top navigation -->
        <app-topnavbar></app-topnavbar>

        <!-- Main view/routes wrapper-->
        <router-outlet></router-outlet>

        <!-- Footer -->
        <app-footer></app-footer>
    </div>
    <!-- End page wrapper-->

</div>
<!-- End wrapper-->

And I want the router-outlet of the register and login component to be wrapped in a layout like this:

<!-- Wrapper-->
<div id="wrapper">

        <!-- Main view/routes wrapper-->
        <router-outlet></router-outlet>

</div>
<!-- End wrapper-->

How can I achieve this?

like image 930
Silthus Avatar asked Sep 19 '25 23:09

Silthus


1 Answers

If I understood correctly, you currently have a root app component, which contains components for header, navigation and footer, each of them controlling a part of the screen.

The short answer to your questions is: yes, a component does not necessarily need to be included in the root AppComponent. You could simply navigate to your LoginComponent using routing from anywhere in your app.

EDIT

You could an additional wrapper for your "basic app layout", say an BasicAppComponent, whose template has this structure:

<!-- Left navigation bar -->
<app-navigation></app-navigation>

<!-- Main page wrapper -->
<div id="page-wrapper" class="gray-bg">

    <!-- Top navigation -->
    <app-topnavbar></app-topnavbar>

    <!-- Main view/routes wrapper-->
    <router-outlet></router-outlet>

    <!-- Footer -->
    <app-footer></app-footer>
</div>
<!-- End page wrapper-->

Then, in your root app component (AppComponent) you will have a structure like this:

<!-- Wrapper-->
<div id="wrapper">

        <!-- Main view/routes wrapper-->
        <router-outlet></router-outlet>

</div>
<!-- End wrapper-->

Additionally, you will build your LoginComponent with the desired structure. The router-outlet from the AppComponent will be replaced by either the BasicAppComponent or the LoginComponent.

like image 125
Tudor Ciotlos Avatar answered Sep 22 '25 18:09

Tudor Ciotlos