在angular-4中从app.component重定向到登录页面?
应用程序组件只有图像。。。从那里我必须重定向到登录页面而不点击任何东西。谁能解释一下这是怎么发生的吗在angular-4中从app.component重定向到登录页面?,angular,Angular,应用程序组件只有图像。。。从那里我必须重定向到登录页面而不点击任何东西。谁能解释一下这是怎么发生的吗 import { Component } from '@angular/core'; @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) export class AppComponent { title = 'app';
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
title = 'app';
}/// app.component.ts
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { LoginComponent } from './login/login.component';
@NgModule({
declarations: [
AppComponent,
LoginComponent
],
imports: [
BrowserModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { } // app.module.ts
您必须使用
@angular/router
模块,定义不同的路由(登录
,主页
,等等)。完成此操作后,您可以在控制器中使用类似的内容:this.router.navigate(['login'])代码>
有关详细信息,请参阅