Skip to main content

Timeline for How to go back last page

Current License: CC BY-SA 4.0

35 events
when toggle format what by license comment
Apr 7, 2020 at 15:32 review Suggested edits
Apr 8, 2020 at 2:24
Feb 20, 2020 at 8:53 review Suggested edits
Feb 20, 2020 at 10:18
S Jan 2, 2020 at 9:58 history suggested Kishan Vaishnav CC BY-SA 4.0
Improved answer by moving important suggestion from comment to answer.
Jan 2, 2020 at 7:06 review Suggested edits
S Jan 2, 2020 at 9:58
May 15, 2019 at 10:52 comment added Andrew Daly how is backClicked() tied to the event?, this function will not run for me.
S Oct 31, 2018 at 14:47 history suggested Machado CC BY-SA 4.0
angular style to code and some minor grammar
Oct 31, 2018 at 14:00 review Suggested edits
S Oct 31, 2018 at 14:47
Apr 18, 2018 at 7:27 review Suggested edits
Apr 18, 2018 at 8:39
Apr 1, 2018 at 9:49 comment added JavierFuentes If you use an anchor instead of a button you will need make it a passive link like this <a href="javascript:void(0)" (click)="goBack()">Back</a> ... as you can see in this response.
Jan 22, 2018 at 18:46 comment added mhodges @Johannes Not having this issue on v4.4.4. Was this on an older version?
Nov 7, 2017 at 19:54 history edited Stefan Falk CC BY-SA 3.0
added 33 characters in body
Oct 24, 2017 at 20:18 history edited Amir Sasson CC BY-SA 3.0
remove redundant code lines
Sep 18, 2017 at 10:21 history edited Ahmad Baktash Hayeri CC BY-SA 3.0
Little bit of grammar fix
Aug 23, 2017 at 12:21 comment added Zymotik Using the router method would run the resolvers again @AndrewWillems
Aug 8, 2017 at 11:50 comment added Sam When I use this._location.back() I get some component null error, which don't happen on using window.history.back(). So maybe it's better to use history.back instead of Location.back?
Jul 20, 2017 at 14:59 review Suggested edits
Jul 21, 2017 at 0:52
Jun 14, 2017 at 22:23 comment added astro8891 There is some bloat/unneeded code in this answer, Hinrich's answer below is the same yet more elegant
May 16, 2017 at 7:07 comment added Amir Sasson @yt61, not sure, maybe re-usability? or if you can get to a specified page from various routes, so you dont know in advance the route to go back to.
May 15, 2017 at 13:40 comment added TomOw Is there any disadvantege of this solution instead of preparing routerLink?
Dec 6, 2016 at 16:31 comment added Demiro-FE-Architect not really... this button is displaying JUST on error.... and I need on the click: if(this.router.previous.has('articleList')){location.back();}else{router.navigate(['/articleList']);} ... The point being, that the previous URL (if coming from article list) might have URL parameters (like filters, pagination, sorting, etc)... and I want the page to go back to that if it's set.... but if a user just navigates to the article from outside source and not via the list (or maybe from a homepage widget) than redirect him to the root of the articleList
Dec 6, 2016 at 16:09 comment added Amir Sasson @DS_web_developer, i think there is not other way but to pragmatically implement what you just described in the Button click handler. like: if(error) then navigate to X, otherwise location.back(). will this be good for you?
Dec 6, 2016 at 15:56 comment added Demiro-FE-Architect How would I do a conditional navigation? let's say I am in an article details page... but an error happens... and I have a buttons saying "error happened, cklick to go back to article list" now, if the previous URL was article list I want to use this._location.back().... if not, I want to use router.navigate(['articleList']);
Sep 19, 2016 at 11:15 comment added Johannes @Andrew: I've encountered the problem, that you cannot go back two times, if you use this.location.back(). You will jump back to the initial site.
Sep 16, 2016 at 14:50 comment added Andrew Willems For what it's worth, the official Angular2 API documentation for Location states: "Note: it's better to use Router service to trigger route changes. Use Location only if you need to interact with or create normalized URLs outside of routing." @Sasxa's answer does apparently show a way to use Router to do this. However, the Location method definitely is more convenient. Does anyone know why the Router method might be more correct than the Location method?
Jul 27, 2016 at 3:24 history edited Amir Sasson CC BY-SA 3.0
added 22 characters in body
Jul 21, 2016 at 13:55 comment added Amir Sasson If you have it built in in the framework, I dont see any reason to use the "native" "window.history.back();" which is an HTML5 feature (developer.mozilla.org/en-US/docs/Web/API/Window/history)
Jul 21, 2016 at 10:00 comment added Johannes Is it correct to assert: never use "window.history.back();" in Angular 2?
Jul 17, 2016 at 19:03 vote accept Hongbo Miao
Jun 9, 2016 at 16:49 vote accept Hongbo Miao
Jul 17, 2016 at 19:01
May 12, 2016 at 14:37 comment added charith.arumapperuma The Location should be imported from "angular2/router" in older releases of Angular 2. In newer releases, it should be from "@angular/common".
May 6, 2016 at 12:39 comment added Amir Sasson hi Justin, please refer to angular.io/docs/js/latest/api/router/… you would see the angular 2 documentation and see that there is a "Built in" back()
May 1, 2016 at 5:23 comment added Justin There is no built in back in the location service
Apr 8, 2016 at 13:52 history edited Amir Sasson CC BY-SA 3.0
deleted 37 characters in body
Apr 7, 2016 at 8:50 review Late answers
Apr 7, 2016 at 8:52
Apr 7, 2016 at 8:29 history answered Amir Sasson CC BY-SA 3.0