Angular2 Check if Location.back has history to go back?

Discussão em 'Angular' iniciado por Keff, Fevereiro 17, 2025.

  1. Keff

    Keff Guest

    So I have a button that calls, Location.back() i want to show it when it has history available, is it posible to check if location has any history, or can go back?

    Or is there a way of accessing the history miself?

    Angular Version: 2.2.3

    HTML:

    <div (click)="historyBack()">
    <i class="fa fa-angle-left"></i>
    </div>


    component:

    import {Location} from '@angular/common';

    @Component(...)
    export class HomeComponent{
    hasHistory = false;
    constructor(
    private _location: Location
    ){
    this.hasHistory = //Magic code
    }
    historyBack(){
    this._location.back();
    }
    }

    Continue reading...

Compartilhe esta Página