vladanPro
vladanPro

Reputation: 513

Angular2: Location two steps back

Is there way to on (click) goBack($event) i need to go back two steps instead just this.location.back() is there list of location array and i need to cut one last element.

Upvotes: 1

Views: 1396

Answers (3)

msanford
msanford

Reputation: 12227

Unless there is absolutely no way that the user can land on this route directly (such as following links, storing a bookmark, or clicking a link in an email, etc) it will be too fragile.

What if someone bookmarked the page but the "home" link actually fires location.back(): they'll end up on whatever site they were on before.

You should use static linking to known routes instead.

Upvotes: 1

Lasse
Lasse

Reputation: 161

If it is back two levels, you should be able to do something like:

this.router.navigate(['../../'], { relativeTo: this.route });

Upvotes: 0

Nilay Vishwakarma
Nilay Vishwakarma

Reputation: 3363

You can use window.history

window.history.go(-2);  

Upvotes: 1

Related Questions