Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

11
  • 3
    I think this is the most elegant solution. Try to merge this code with the new filter & pairwise solution of: stackoverflow.com/a/35287471/518879 Commented Apr 28, 2018 at 23:21
  • 3
    Ps. Don't forget to add this RouterExtService to the apps-routing.module.ts (in my case), like so: @NgModule({ ..., providers: [RouterExtService]}) export class AppRoutingModule { } Commented Apr 28, 2018 at 23:50
  • OK there is a big problem with this service solution.. In my case I call the routerExtService.getPreviousUrl() method in the constructor of a service used in a component. For some reason this called earlier than the actual update. Meaning we have a timing dependency! I think its much easier to use Subject. Commented Apr 29, 2018 at 0:28
  • Well, it worked fine for me in a small project. Maybe it needs some tweak to suit your needs. Have you solved the issue? Commented May 11, 2018 at 19:47
  • I'm currently using the so called URL Matrix parameters to 'store' my state in my URL, by default the browser URL stores the state now when using the back button. let params = new HttpParams({fromString: retrieveURL}).set('name', 'victor') const paramsObject = params.keys().reduce((obj, key) => { obj[key] = params.get(key) return obj }, {}) this.router.navigate([paramsObject], { relativeTo: this.route }) Commented May 11, 2018 at 23:28