我有一個登錄頁面,有一個窗體和一個按鈕來做登錄。當用戶點擊按鈕時,我想評估密碼和電子郵件,如果一切正確,用戶必須重定向到另一個頁面。重定向到另一頁Angular 2
我的問題是我在裏面的登錄html這(<router-outlet></router-outlet>)
新頁面的所有信息都顯示在登錄頁面的相同位置,我不想混合這兩個信息。我想要登錄單獨的新信息。
我嘗試使用window.location.href,但不工作的信息繼續顯示在登錄的相同的地方。
這是我的路由配置。
export const routes: Routes = [
{ path: 'show_alunos', component: ListAlunosComponent }
];
組件ListAlunosComponent是我想在驗證用戶憑據後顯示的新頁面。
app.component.html
<form class="form-signin">
<h2 class="form-signin-heading">Please sign in</h2>
<label for="inputEmail" class="sr-only">Email address</label>
<input [(ngModel)]="email" name="email" type="email" id="inputEmail" class="form-control" placeholder="Email address" required autofocus>
<label for="inputPassword" class="sr-only">Password</label>
<input [(ngModel)]="password" name="password" type="password" id="inputPassword" class="form-control" placeholder="Password" required>
<div class="checkbox">
<label>
<input type="checkbox" value="remember-me"> Remember me
</label>
</div>
<button class="btn btn-lg btn-primary btn-block" (click)="submit()" type="submit">Sign in</button>
</form>
<router-outlet></router-outlet>
app.component.ts
mport { 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 = 'app';
public email: string;
public password: string;
constructor(private router: Router) {
this.email = "";
this.password = "";
}
public submit(): void {
this.router.navigateByUrl(['show_alunos']);
}
}
app.router.ts
import { ModuleWithProviders } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { AppComponent } from './app.component';
import { ListAlunosComponent } from '../pages/list-alunos/list-
alunos.component';
// Route Configuration.
export const routes: Routes = [
{ path: 'show_alunos', component: ListAlunosComponent }
];
export const routing: ModuleWithProviders = RouterModule.forRoot(routes);
您確切的問題是什麼? – k11k2
可能重複[Angular 2 - 成功登錄後不工作重定向](https://stackoverflow.com/questions/35479144/angular-2-redirect-after-successful-login-not-working) –