我想路由两个简单的页面。 如果我从登录页面在仪表板上路由,但登录页面也显示在仪表板页面上。 需要帮助。
代码如下:
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
title = 'to my First Angular App !';
}
.......................
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { Router, RouterModule} from '@angular/router';
import { AppComponent } from './app.component';
import { DashboardComponent } from './dashboard/dashboard.component';
@NgModule({
declarations: [
AppComponent,
DashboardComponent,
],
imports: [
BrowserModule,
FormsModule,
RouterModule.forRoot([
{path: 'dashboard', component: DashboardComponent}
])
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
答案 0 :(得分:0)
您应该修改路由:
{path: 'login', component: AppComponent},
{path: 'dashboard', component: DashboardComponent}