Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to go back last page

Is there a smart way to go back last page in Angular 2?

Something like

this._router.navigate(LASTPAGE); 

For example, page C has a Go Back button,

  • Page A -> Page C, click it, back to page A.

  • Page B -> Page C, click it, back to page B.

Does router have this history information?

like image 441
Hongbo Miao Avatar asked Feb 17 '16 02:02

Hongbo Miao


People also ask

How do you go back to previous page on keyboard?

Right-click, or click and hold either the Back or Forward arrow in the browser toolbar. Goes to the previous page in your browsing history for the tab. Press Backspace , or Alt and the left arrow together.

How do I go to the last page on my laptop?

No, by far the best way to jump to the top or bottom of a Web page is by tapping your Home or End key, respectively. This works in Chrome, Firefox, and Internet Explorer (and probably every other browser as well–those are just the ones I've tested). Try it–I guarantee it'll join your list of favorite shortcuts.

How do I go back to previous page in JavaScript?

The history. back() method loads the previous URL (page) in the history list. The history. back() method only works if a previous page exists.

How do I go back to previous page in Firefox?

In the current version of Firefox, which is Firefox 84 as of now, you can use either Backspace, Alt + Left arrow, or a toolbar button to go to a previous web site (if any) on Windows.


1 Answers

Actually you can take advantage of the built-in Location service, which owns a "Back" API.

Here (in TypeScript):

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();   } } 

Edit: As mentioned by @charith.arumapperuma Location should be imported from @angular/common so the import {Location} from '@angular/common'; line is important.

like image 55
Amir Sasson Avatar answered Oct 06 '22 02:10

Amir Sasson