小编Ani*_*hKr的帖子

如何导航(重定向)到 Angular 中的另一个页面?

单击按钮时我试图重定向到另一个页面(Page-II),但不幸的是另一个页面组件加载在同一页面(Page-I)上。到目前为止我尝试过的:

应用程序组件.html

<button (click)="register()"
  mat-raised-button class="searchButton" type="button">Register</button>
  <button (click)="profile()"
  mat-raised-button class="searchButton" type="button">Profile</button>
 <router-outlet></router-outlet>
Run Code Online (Sandbox Code Playgroud)

应用程序路由.module.ts

const routes: Routes = [{
  path : 'register',
  component : RegisterComponent
},
{
  path : 'profile',
  component : ProfileComponent
}];

@NgModule({
  imports: [RouterModule.forRoot(routes)],
  exports: [RouterModule]
})

export class AppRoutingModule { }
Run Code Online (Sandbox Code Playgroud)

应用程序组件.ts

import { Component , OnInit } from '@angular/core';
import { Router } from '@angular/router';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
  title = 'app';
  constructor(private router: Router …
Run Code Online (Sandbox Code Playgroud)

html typescript angular

2
推荐指数
1
解决办法
1万
查看次数

标签 统计

angular ×1

html ×1

typescript ×1