Redirect to home page after successful login using routes in Angular

AliYilmaz
 
on Nov 29, 2021 12:20 AM
378 Views

Hi,

Is there a problem with my build? There are Header and Footer components. There is also Home Component. I am adding App Component only router-outlet. 

If I add app component app home, this time it shows home on all pages.

<app-home></app-home>

How should I do in this case? 

Header Component - The menus html

Footer Component - The footer html

Home Component

<app-header></app-header>    
    <div class="content-wrapper">  
    </div>  
<app-footer></app-footer>  

App Component 

<router-outlet></router-outlet>  

my problem is that after logging in it does not redirect to the home page.

When I look at the browser, the page it is directed to still appears as the login page.

what should i do in this situation

Login Component

this.service.login(tvalue.subscribe(res=>{
    this.router.navigate(['/home']);
}

Routes 

const routes: Routes = [
  {path:'',redirectTo:'/login',pathMatch:'full'},
  {path:'login',component:LoginComponent},
  { path:'home',component:HomeComponent},
Download FREE API for Word, Excel and PDF in ASP.Net: Download
AliYilmaz
 
on Nov 30, 2021 12:39 AM

Hi,

I solved this problem. 

If anyone has the same problem, this code will solve it.

this.service.login(this.kisiForm.value).subscribe(res=>{
    this.router.navigate(['/home']).then(()=> window.location.reload());     
}