Hi,
Kindly let me know how to redirect from one component to another in Angualar 8
like Login component to Homepage component.
Thanks
Sathish
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Sanwar RanwaRank #23 · 44.7K reputationPosted Jul 23, 2019, 10:11 PM EDT
Sivakumar KonetiRank #1,556 · 1K reputationPosted Jul 24, 2019, 11:13 PM EDT
Chittaranjan SwainRank #216 · 11.3K reputationPosted Jul 28, 2019, 11:19 PM EDT
Sandhiya PriyaRank #26 · 43.2K reputationPosted Jan 5, 2026, 11:25 PM EST
In Angular 8, redirecting from one component to another is done using the Angular Router. You don’t “switch components” directly — instead, you navigate to a route that loads the target component.
Steps to Redirect (Login ? Homepage)
1. Configure Routes
In
app-routing.module.ts:import { NgModule } from '@angular/core'; import { RouterModule, Routes } from '@angular/router'; import { LoginComponent } from './login/login.component'; import { HomeComponent } from './home/home.component'; const routes: Routes = [ { path: 'login', component: LoginComponent }, { path: 'home', component: HomeComponent }, { path: '', redirectTo: '/login', pathMatch: 'full' } // default route ]; @NgModule({ imports: [RouterModule.forRoot(routes)], exports: [RouterModule] }) export class AppRoutingModule { }2. Inject Router in Login Component
In
login.component.ts:import { Component } from '@angular/core'; import { Router } from '@angular/router'; @Component({ selector: 'app-login', templateUrl: './login.component.html' }) export class LoginComponent { constructor(private router: Router) {} onLogin() { // After successful login logic this.router.navigate(['/home']); // redirect to HomeComponent } }3. Add Router Outlet
In
app.component.html:This is where Angular loads the component based on the route.
4. Example Flow
User opens
/login?LoginComponentloads.On successful login ?
this.router.navigate(['/home']).Angular loads
HomeComponentinto.Summary
Define routes in
app-routing.module.ts.Use
Routerservice to navigate programmatically.acts as the placeholder for components.