我有一个登录页面和仪表板组件。我的问题是,当我从页面登录时,仪表板显示在登录页面下方,而不是重定向为新页面。如何在 Angular 7 中实现这一点?任何帮助都将是有用的。谢谢!
app.component.ts
这是我的路由模块。
app-routing.module.ts
app.component.ts
import { Component } from '@angular/core';
import { Router } from '@angular/router';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
title = 'Shopping-cart';
user = []
users = []
public Candidate = []
public showWhen:boolean = false;
constructor(private _router: Router){}
authenticateLogin(user){
let authUser = JSON.parse(localStorage.getItem('auth'))
console.log(user);
if(user.mail === authUser[0] && user.password === authUser[1]){
this.showWhen = true;
console.log("Logged in Successfully");
this._router.navigate(['dashboard']);
} else {
console.error("Invalid email and password");
}
}
}
这是我的路由模块。
app-routing.module.ts
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { DashboardComponent } from './dashboard/dashboard.component';
const routes: Routes = [
{ path: 'dashboard', component: DashboardComponent}
];
@NgModule({
imports: [RouterModule.forRoot(routes, { enableTracing: true })],
exports: [RouterModule]
})
export class AppRoutingModule { }