marcel
marcel

Reputation: 3272

Angular2 Browser History Navigation

How to navigate to previous state and back in the browser history.

I remember AngularJS supported this:

$window.history.back();

React supports this:

import { browserHistory } from 'react-router'
browserHistory.goBack();

How to back and previous browser history in Angular 2 >= v2.1.0

Upvotes: 3

Views: 6394

Answers (1)

Sanket
Sanket

Reputation: 20017

You can use built in Location service, which has back api.

Sample code-

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


@Component({ .... })
class AppComponent {
    constructor(private _location: Location) {
    }
    backClicked() {
        this._location.back();
    }
}

Reference: https://angular.io/docs/ts/latest/api/common/index/Location-class.html

See if this helps.

Upvotes: 8

Related Questions