Skip to content

Instantly share code, notes, and snippets.

@kavicastelo
Created April 23, 2025 15:48
Show Gist options
  • Select an option

  • Save kavicastelo/140d73279ca2ef24d1982b578d04ab43 to your computer and use it in GitHub Desktop.

Select an option

Save kavicastelo/140d73279ca2ef24d1982b578d04ab43 to your computer and use it in GitHub Desktop.
Angular Learning Module 3 (Interns) – Reusable Layout + Navigation + Feature Modules
import { Routes } from '@angular/router';
import { LayoutComponent } from './layout/layout.component';
import { DashboardComponent } from './dashboard/dashboard.component';
import { ProfileComponent } from './profile/profile.component';
import { MessagesComponent } from './messages/messages.component';
export const routes: Routes = [
{
path: '',
component: LayoutComponent,
children: [
{ path: 'dashboard', component: DashboardComponent },
{ path: 'profile', component: ProfileComponent },
{ path: 'messages', component: MessagesComponent },
{ path: '', redirectTo: 'dashboard', pathMatch: 'full' }
]
},
{ path: '**', redirectTo: '' }
];
import { Component } from '@angular/core';
import { CommonModule } from '@angular/common';
@Component({
selector: 'app-dashboard',
standalone: true,
imports: [CommonModule],
template: `<h2>Welcome to the Dashboard</h2>`
})
export class DashboardComponent {}
header {
background: #222;
color: #fff;
padding: 1rem;
text-align: center;
}
.container {
display: flex;
}
nav {
width: 200px;
background: #f5f5f5;
padding: 1rem;
display: flex;
flex-direction: column;
gap: 10px;
}
nav a {
text-decoration: none;
color: #333;
}
nav a.active {
font-weight: bold;
color: #007bff;
}
main {
flex: 1;
padding: 1rem;
}
<header>
<h1>My Intern Dashboard</h1>
</header>
<div class="container">
<nav>
<a routerLink="/dashboard" routerLinkActive="active">Dashboard</a>
<a routerLink="/profile" routerLinkActive="active">Profile</a>
<a routerLink="/messages" routerLinkActive="active">Messages</a>
</nav>
<main>
<router-outlet></router-outlet>
</main>
</div>
import { Component } from '@angular/core';
import { RouterModule } from '@angular/router';
import { CommonModule } from '@angular/common';
@Component({
selector: 'app-layout',
standalone: true,
imports: [CommonModule, RouterModule],
templateUrl: './layout.component.html',
styleUrls: ['./layout.component.css'],
})
export class LayoutComponent {}
import { Component } from '@angular/core';
import { CommonModule } from '@angular/common';
@Component({
selector: 'app-messages',
standalone: true,
imports: [CommonModule],
template: `
<h2>Messages</h2>
<ul>
<li *ngFor="let msg of messages">{{ msg }}</li>
</ul>
`
})
export class MessagesComponent {
messages = ['Hello!', 'Remember to push your code.', 'Great job so far!'];
}
import { Component } from '@angular/core';
import { CommonModule } from '@angular/common';
@Component({
selector: 'app-profile',
standalone: true,
imports: [CommonModule],
template: `
<h2>User Profile</h2>
<p>Name: Intern</p>
<p>Role: Frontend Learner</p>
`
})
export class ProfileComponent {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment