Skip to content

Instantly share code, notes, and snippets.

@raido
Created April 23, 2021 13:09
Show Gist options
  • Save raido/4f3b60b9cfecdc9e02e0e1551394911e to your computer and use it in GitHub Desktop.
Save raido/4f3b60b9cfecdc9e02e0e1551394911e to your computer and use it in GitHub Desktop.
import Service, { inject as service } from "@ember/service";
import RouterService from "@ember/routing/router-service";
export default class RouterWithBackButtonService extends Service {
@service("router")
router!: RouterService;
previousURL = "";
setup() {
this.router.on("routeWillChange", () => {
this.previousURL = this.router.currentURL;
});
}
goBack() {
if (!this.previousURL) {
return;
}
this.router.transitionTo(this.previousURL);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment