Going back to the previous page in Angular is fairly simple:
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 is the equivalent of hitting your browser's "back" button. But how can this code be modified such that if this._location.back() is going to take you to a url outside of the app, that it instead redirects you to a route inside the app.
For example, say you're at Google.com and then you paste in my-app.com/page-foo and navigate that way. this._location.back() will take you back to Google.com, but I want it to instead navigate to my-app.com/page-bar.