I am trying to navigate to /login page whenever user clicks on the Login/Signup option present in my header component. But, whenever I clicks on Login/signUp it remains on the same page.
My app-routing.module.ts file is as below
import {NgModule} from '@angular/core';
import {RouterModule, Routes} from '@angular/router';
import {LoginComponent} from './modules/login/login.component';
import {BlogComponent} from './modules/blog/blog.component';
const routes: Routes = [
{
path: '',
redirectTo: 'blog',
pathMatch: 'full'
},
{
path: 'login',
component: LoginComponent
},
{
path: 'blog',
component: BlogComponent,
children: [
{
path: '**',
component: BlogComponent
}
]
},
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule {
}
import {NgModule} from '@angular/core';
import {RouterModule, Routes} from '@angular/router';
import {LoginComponent} from './modules/login/login.component';
import {BlogComponent} from './modules/blog/blog.component';
const routes: Routes = [
{
path: '',
redirectTo: 'blog',
pathMatch: 'full'
},
{
path: 'login',
component: LoginComponent
},
{
path: 'blog',
component: BlogComponent,
children: [
{
path: '**',
component: BlogComponent
}
]
},
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule {
}
and the HTML tag from which I am trying to call this is placed in my header.component.html
<a data-toggle="tooltip" title="Sign In/Sign Up" routerLink="/login" routerLinkActive="active" class="login">Login/SignUp</a>
Also I have added router-outlet in my app.component.html
<app-header></app-header>
<router-outlet></router-outlet>
<app-footer></app-footer>
Though when I manually navigates to the login page i.e. by entering localhost:4200/login in browser, it successfully opens the login page.
My complete code can be found here -
https://github.com/vibhorgoyal18/atest-blog/tree/master/src/app