I am making a normal login with username and password admin & admin.In login component navigate to layout.But i am getting an error like "core.js:1448 ERROR Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'layout'".please help me..
app.routing.module.ts
import {NgModule} from '@angular/core';
import {RouterModule} from '@angular/router';
@NgModule({
imports: [
RouterModule.forRoot([
{path: '', redirectTo: '/login', pathMatch: 'full'},
{path: 'login', loadChildren: 'app/login/login.module#LoginModule'}
])
],
exports: [
RouterModule
]
})
export class AppRoutingModule {
}
my login.component.ts is
import { Component, OnInit } from '@angular/core';
import { Router, ActivatedRoute } from '@angular/router';
import { AuthenticationService } from '../../services/authentication.service';
@Component({
selector: 'app-login',
templateUrl: './login.component.html',
styleUrls: ['./login.component.css']
})
export class LoginComponent implements OnInit {
username:string;
password:string;
constructor(
public authService: AuthenticationService,
private route: ActivatedRoute,
private router: Router) { }
ngOnInit() {
}
login(){
if(this.authService.login(this.username, this.password)){
this.router.navigate(['/layout']);
}
}
}
my login.routing.module.ts is
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { LoginComponent } from './login/login.component';
import { LayoutComponent } from '../layout/layout/layout.component';
import { LayoutRoutingModule } from '../layout/layout-routing.module';
const routes: Routes = [
{ path: '', component: LoginComponent },
{ path: 'layout', component: LayoutComponent }
];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule]
})
export class LoginRoutingModule { }