Backpage Anch

⚡ 👉🏻👉🏻👉🏻 INFORMATION AVAILABLE CLICK HERE 👈🏻👈🏻👈🏻
Newfoundland and Labrador
Newfoundland & Labrador
Northwest Territories
Northwest Territories
Sign up or log in to customize your list.
Join Stack Overflow to learn, share knowledge, and build your career.
Sign up with email Sign up Sign up with Google Sign up with GitHub Sign up with Facebook
Connect and share knowledge within a single location that is structured and easy to search.
Is there a smart way to go back last page in Angular 2?
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?
29.8k4545 gold badges115115 silver badges201201 bronze badges
Actually you can take advantage of the built-in Location service, which owns a "Back" API.
Edit: As mentioned by @charith.arumapperuma Location should be imported from @angular/common so the import {Location} from '@angular/common'; line is important.
1,08577 silver badges2222 bronze badges
8,75711 gold badge1111 silver badges2323 bronze badges
The Location should be imported from "angular2/router" in older releases of Angular 2. In newer releases, it should be from "@angular/common". – charith.arumapperuma May 12 '16 at 14:37
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) – Amir Sasson Jul 21 '16 at 13:55
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? – Andrew Willems Sep 16 '16 at 14:50
@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. – Johannes Sep 19 '16 at 11:15
@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. – Amir Sasson May 16 '17 at 7:07
In the final version of Angular 2.x / 4.x - here's the docs https://angular.io/api/common/Location
1,28911 gold badge1717 silver badges3636 bronze badges
11.5k44 gold badges3737 silver badges5252 bronze badges
While navigating back to previous screen can we retain input entered values without using a object in service. – Vignesh Dec 26 '18 at 4:28
How to show back animation while location.back() is executing? – Snow Bases Jan 3 '20 at 8:18
You can put this into a directive, that can be attached to any clickable element:
15.6k1010 gold badges4040 silver badges6969 bronze badges
16.2k77 gold badges4545 silver badges8989 bronze badges
If you refresh on this page, and click on the button that triggers "this.location.back()", it will just trigger a page refresh. Is there any way that the Location module can detect if previous path exists? – Henry Jan 9 '20 at 2:27
Keep in mind if a user went directly to a page where Back button exists and if he clicks on a button.. then he will be throw out of the app to the previous page according to the browser(platform) history. – hastrb Apr 24 '20 at 8:23
If you use an anchor instead of a button you must make it a passive link with href="javascript:void(0)" to make Angular Location work.
1,5041414 silver badges1212 bronze badges
I would suggest creating a 'clickPreventDefault' directive rather than using javascript:void(0). Something like... @Directive({ selector: '[clickPreventDefault]' }) export class ClickPreventDefaultDirective { @HostListener("click", ["$event"]) onClick($event: Event) { $event.preventDefault(); } } – bmd Apr 10 '18 at 10:22
Thank you @bmd , it's a more elaborate way but it works too. Another working solution is don't use herf: although this way don't pass HTML Validators. – JavierFuentes Apr 12 '18 at 8:59
You can implement routerOnActivate() method on your route class, it will provide information about previous route.
Then you can use router.navigateByUrl() and pass data generated from ComponentInstruction. For example:
39.8k2626 gold badges111111 silver badges128128 bronze badges
36.2k1414 gold badges8585 silver badges9898 bronze badges
Is this still valid for Angular 2.1.0? – smartmouse Oct 21 '16 at 14:43
@smartmouse I don't think so, there is documentation for routerOnActivate – Bojan Kogoj Oct 28 '16 at 9:48
The routerOnActivate() link in this answer is broken. Seems this is not the way to do it in release version. – rmcsharry Feb 7 '17 at 19:44
After all these awesome answers, I hope my answer finds someone and helps them out. I wrote a small service to keep track of route history. Here it goes.
1,35122 gold badges1717 silver badges2828 bronze badges
After trying more or less all solutions, I find this one is the more consistent way to do that – A. D'Alfonso Mar 27 '19 at 16:44
What if I open the page on particular link and I want that it will go back to page that in page tree? – Ivan Feb 11 '20 at 8:45
Iḿ getting error Type string has no call signatures when calling preiousUrl(). Can you help me out? :D – Szoke Lori Jul 27 '20 at 9:50
@SzokeLori Sounds like your "this" is pointing to String type. You should post a question with the code. – Anjil Dhamala Jul 27 '20 at 14:03
@AnjilDhamala well... i just injected the thing as private to constructor and wanted to console log it. Mind me, im a beginner – Szoke Lori Jul 27 '20 at 16:47
Also work for me when I need to move back as in file system. P.S. @angular: "^5.0.0"
I was hopeful this would work, but this moves back to the next Route above it - not to the route you were on before navigating to the page. Good to know this exists, but if you have multiple entry points for your component, this method will only ever go back to the route above it, not where you originated from. – Scott Byers Jan 9 '18 at 22:44
As I write "when I need to move back as in file system" :) For me, this behavior was also unexpected. – Shevtsiv Andriy Jan 23 '18 at 13:39
You're confusing back (e.g. cd -) with up (cd ..). Nevertheless, it's handy to know this works. – devios1 Jan 26 at 14:41
I made a button I can reuse anywhere on my app.
Then add it to any template when you need a back button.
Note: This is using Angular Material, if you aren't using that library then remove the mat-button and color.
4,63911 gold badge2727 silver badges3636 bronze badges
Does this approach work with named router outlets though? Say I have several on the page and only want to go back on one of them, would this work? – rrd Feb 9 '18 at 10:25
You'll have to use a different approach for that situation. If you had the same back button in two different router outlets, they will probably both do the same thing and go back on the last router outlet that was changed. – Todd Skelton Feb 14 '18 at 23:00
For named outlets, I found that this approach worked: this.router.navigate(['../'], {relativeTo: this.route}) – rrd Feb 15 '18 at 8:11
How to use this component inside another component? – RN Kushwaha May 29 '19 at 12:21
The way I did it while navigating to different page add a query param by passing current location
Read this query param in your component
If returnUrl is present enable the back button and when user clicks the back button
This should able to navigate to previous page. Instead of using location.back I feel the above method is more safe consider the case where user directly lands to your page and if he presses the back button with location.back it will redirects user to previous page which will not be your web page.
80977 silver badges99 bronze badges
Need to import ActivatedRoute and use that instead of Router on the queryParams subscription (e.g., this.route.queryParams.subscribe), but otherwise, seems to work! – Stephen Kaiser Jun 13 '17 at 23:12
for me it is working fine with router itself even in angular 4 – Puneeth Rai Jun 15 '17 at 10:53
Best answer, but in Angular 5 (up to x?) you need to inject an object of "ActivatedRoute" and use queryParams on this object, as Stephen Kaiser already stated. – Satria Jan 10 '20 at 12:54
8,31322 gold badges2222 silver badges4141 bronze badges
This is a complement to an answer but not an answer itself – Double Expresso Aug 25 '20 at 8:57
To go back without refreshing the page, We can do in html like below javascript:history.back()
7,03822 gold badges2525 silver badges3030 bronze badges
I would recommend using Location service instead. official API – hastrb Apr 24 '20 at 8:29
import {Location} from 'angular2/platform/common';
Works for me location.back() also works but not I compile with --prod – Alex Feb 25 '20 at 19:03
in angular 4 use preserveQueryParams, ex:
When clicking the link, you are redirected edit/10?page=1, preserving params
8,31322 gold badges2222 silver badges4141 bronze badges
yes you can do it. write this code on your typescript component and enjoy!
Thanks for contributing an answer to Stack Overflow!
By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy
The Remote CompanyNo office location
Senior Full Stack Engineer with a love for React, Node & Typescript REMOTE
Authority PartnersNo office location
Senior Vue.js Frontend Developer (m/f/x)
To subscribe to this RSS feed, copy and paste this URL into your RSS reader.
site design / logo © 2021 Stack Exchange Inc; user contributions licensed under cc by-sa. rev 2021.2.16.38590
Символы и знаки в помощь. АНКХ | Марсельcкое Время | Яндекс Дзен
Free Classified sites | New Backpage Alternative | Backpage Replacement
angular - How to go back last page - Stack Overflow
Анкх в Беларуси. Сравнить цены, купить потребительские товары на...
How to Use Backpage - Backpage Tutorial - YouTube
Muskegon Skipthegames
Huntsville Female Escorts
Sammy Braddy Boobpedia
Backpage Anch










































