Categories
Angular Answers

How to go back last page with Angular?

Spread the love

Sometimes, we want to go back last page with Angular.

In this article, we’ll look at how to go back last page with Angular.

How to go back last page with Angular?

To go back last page with Angular, we can call the location.back method.

For instance, we write

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

@Component({
  // ...
})
class SomeComponent {
  constructor(private location: Location) {}

  backClicked() {
    this.location.back();
  }
}

to inject location in the `constructor.

Then in the onClick method, we call this.location.back to go back to the last page.

How to go back last page with Angular?

To go back last page with Angular, we can call the location.back method.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *