[英]Angular: How can I go to a different route when I click a button twice?
First I show the home page.首先我显示主页。
After I click the "Sayfaya git" button it shows the list page.单击“Sayfaya git”按钮后,它会显示列表页面。
What I want to do is: When I click the button again it should go to the home page.我想要做的是:当我再次单击该按钮时,它应该 go 到主页。
how can i do that?我怎样才能做到这一点?
app.component.html app.component.html
<div>
<h1>Merhaba dünya</h1>
<button [routerLink]="['/list']" > Sayfaya git</button>
</div>
<div>
<router-outlet></router-outlet>
</div>
Routes路线
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import {HomeComponent} from './home/home.component';
import {ListComponent} from './list/list.component';
const routes: Routes = [
{path:"",component: HomeComponent},
{path:"list",component: ListComponent},
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule { }
Use dblclick
使用dblclick
<button (click)="onSingleClickNavigate()"
(dblclick)="onDoubleClickNavigate($event)"
>Sayfaya git</button>
import { Router } from '@angular/router';
constructor(private router: Router) {}
onSingleClickNavigate() {
this.router.navigate(['/list']);
}
onDoubleClickNavigate(event) {
event?.preventDefault(); // Prevents single click behavior
this.router.navigate(['/home']);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.