Angular 4,登录内容页面在仪表板页面中显示

时间:2017-12-19 17:52:27

标签: angular

我想路由两个简单的页面。 如果我从登录页面在仪表板上路由,但登录页面也显示在仪表板页面上。 需要帮助。

代码如下:

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 { }

1 个答案:

答案 0 :(得分:0)

您应该修改路由:

{path: 'login', component: AppComponent},
{path: 'dashboard', component: DashboardComponent}