I have an angular 2 application that I can not get to route correctly.
I am in the child component trying to route to another component at the
parent level but I keep getting a "Cannot match any routes" error.
I have tried using "../" and sending the relative path, but to no avail.
Here is the code:
App Module:
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
import { AppRouter } from './AppRouter.module';
import { } from '@angular/router';
import { AppComponent } from '../Components/app.component';
import { LoginComponent } from '../Components/login.component';
import { MenuComponent } from '../Components/menu.component';
@NgModule({
imports: [
BrowserModule,
FormsModule,
HttpModule,
AppRouter
],
declarations: [
AppComponent,
LoginComponent,
MenuComponent
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
Router Module:
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { LoginComponent } from '../Components/login.component';
import { MenuComponent } from '../Components/menu.component';
const routes: Routes = [
{ path: '', redirectTo: '/login', pathMatch: 'full' },
{ path: 'login', component: LoginComponent },
{ path: 'menu', component: MenuComponent }
];
@NgModule({
imports: [ RouterModule.forRoot(routes) ],
exports: [ RouterModule ]
})
export class AppRouter {}
LoginModule:
import { Component } from '@angular/core';
import { Router } from '@angular/router';
@Component({
templateUrl: '../Templates/login.component.html'
})
export class LoginComponent {
title = 'app works!';
username: string = 'user';
password: string = 'password'
constructor(private router: Router){
}
validate(): void{
if(this.username === "user" &&
this.password === "password"){
console.log("Logged In!");
this.router.navigate(['/main']);
}
else {
console.log(this.username + ' ' + this.password);
}
}
}
Any ideas would be greatly appreciated. Thanks.
--
You received this message because you are subscribed to the Google Groups
"Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.