0

Something like

For example, page C has a Go Back button,

Page A -> Page B -> Page C, click it, back to page A and keep the page A do not refresh

Does router can be achieved? Thanks

yang yang
  • 9
  • 1
  • What's the problem? Could you clarify your question? – LoïcR Dec 22 '16 at 09:20
  • like this? http://stackoverflow.com/questions/35446955/how-to-go-back-last-page-in-angular-2 – Ric Dec 22 '16 at 09:22
  • I mean I click one button in page a to get to page B, and then click one button in page B to get to page C. And now I want to achieve that by click one button in Page C to back to Page A without refreshing page A – yang yang Dec 22 '16 at 09:38
  • it seems that below method is not work import {Component} from '@angular/core'; import {Location} from '@angular/common'; @Component({ directives: [ROUTER_DIRECTIVES] }) @RouteConfig([ {...}, ]) class AppCmp { constructor(private _location: Location) { } backClicked() { this._location.back(); } } – yang yang Dec 22 '16 at 09:40
  • 1
    maybe you're missing some dependencies? – Ric Dec 22 '16 at 09:50

1 Answers1

0

This is the best way:

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

@Component({
// component's declarations here
})
class SomeComponent {
    constructor(private location: Location) {
    }
    backClicked() {
        this.location.back();
    }
}

This works fine!

First: Import Location as in the line 2; Second: Inject in the constructor as in the line; Third: Use calling this.location.back();, where location is the name declared in the constructor

source: How to go back last page