Reputation: 566
First I show the home page.
After I click the "Sayfaya git" button it shows the list page.
What I want to do is: When I click the button again it should go to the home page.
how can i do that ?
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 { }
Upvotes: 1
Views: 210
Reputation: 2623
Use 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']);
}
Upvotes: 2