简体   繁体   English

在angular-4中从app.component重定向到登录页面?

[英]redirect in angular-4 from app.component to login page?

app component have just image... from there i have to redirect to login page without clicking anything. 应用程序组件只有图像...从那里我必须重定向到登录页面,而无需单击任何东西。 can anyone explain me how it happens? 谁能解释我的情况?

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

You have to use @angular/router module, define different routes ( login , home , etc.). 您必须使用@angular/router模块,定义不同的路由( loginhome等)。 After you do that, you can use something like this in your controller: this.router.navigate(['login']); 完成此操作后,您可以在控制器中使用以下this.router.navigate(['login']);this.router.navigate(['login']); .

Please refer to the official documentation for more details. 请参阅官方文档以获取更多详细信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM