{"id":15535125,"url":"https://github.com/jasonmit/ember-onbeforeunload","last_synced_at":"2025-09-22T21:38:40.913Z","repository":{"id":17537713,"uuid":"20340373","full_name":"jasonmit/ember-onbeforeunload","owner":"jasonmit","description":"invoke logic when transitioning between routes or closing window","archived":false,"fork":false,"pushed_at":"2022-12-10T20:27:09.000Z","size":4185,"stargazers_count":30,"open_issues_count":27,"forks_count":6,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-04-15T07:27:21.923Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jasonmit.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-05-30T19:43:07.000Z","updated_at":"2023-11-20T08:14:24.000Z","dependencies_parsed_at":"2023-01-14T00:30:19.823Z","dependency_job_id":null,"html_url":"https://github.com/jasonmit/ember-onbeforeunload","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jasonmit%2Fember-onbeforeunload","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jasonmit%2Fember-onbeforeunload/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jasonmit%2Fember-onbeforeunload/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jasonmit%2Fember-onbeforeunload/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jasonmit","download_url":"https://codeload.github.com/jasonmit/ember-onbeforeunload/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248689869,"owners_count":21146020,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-02T11:44:35.321Z","updated_at":"2025-09-22T21:38:35.861Z","avatar_url":"https://github.com/jasonmit.png","language":"JavaScript","readme":"# ember-onbeforeunload\n[![npm Version][npm-badge]][npm]\n[![Build Status][travis-badge]][travis]\n[![Ember Observer Score](https://emberobserver.com/badges/ember-onbeforeunload.svg)](https://emberobserver.com/addons/ember-onbeforeunload)\n\nAn add-on to conditionally prompt the user when transitioning between routes or closing the browser.\n\n## Installation\nThis library is tested against Ember 1.13.x and Ember 2.x.\n\n```\nember install ember-onbeforeunload\n```\n\n## Usage\nTo get started, mix the `ConfirmationMixin` into your `Ember.Route`. By default,\nthe user will be prompted beforeunload any time the `model` for the route\n`hasDirtyAttributes` ([docs](http://emberjs.com/api/data/classes/DS.Model.html#property_hasDirtyAttributes)).\n\n```js\n// app/routes/foo.js\nimport Ember from 'ember';\nimport ConfirmationMixin from 'ember-onbeforeunload/mixins/confirmation';\n\nexport default Ember.Route.extend(ConfirmationMixin, { });\n```\n\n## Customization\nThis addon tries to provide sane defaults, but it also exposes all of the internals\nfor customization.\n\n### Confirmation Message\nYou can customize the message displayed in the confirmation dialog by overriding\nthe `confirmationMessage` property. You can either pass a hard-coded string,\nor use a function.\n\n```javascript\nexport default Ember.Route.extend(ConfirmationMixin, {\n  confirmationMessage: 'Are you sure?',\n});\n```\n\n```javascript\nexport default Ember.Route.extend(ConfirmationMixin, {\n  confirmationMessage(model) {\n    return `Are you sure you want to unload ${model.name}?`;\n  }\n});\n```\n\n```javascript\nexport default Ember.Route.extend(ConfirmationMixin, {\n  i18n: service(), // see ember-i18n\n  confirmationMessage() {\n    return this.get('i18n').t('myTranslation');\n  }\n});\n```\n\n### isPageDirty logic\nIf you do not sure Ember Data, or you have other logic to determine whether or\nnot the page is dirty, you can override the `isPageDirty` method.\n\n```javascript\nexport default Ember.Route.extend(ConfirmationMixin, {\n  isPageDirty(/* model */) {\n    const isDirty = true; // your logic here\n    return isDirty;\n  }\n});\n```\n\n### Allow Dirty Transitions\nBy default, we allow navigating within the hierarchy of route you mix the\n`ConfirmationMixin` into. For example, navigating from `myroute.index` to\n`myroute.index.subroute` would not check `isPageDirty`. If you have other logic\nthat determines when a dirty transition should be allowed, you can override\n`shouldCheckIsPageDirty`.\n\n```javascript\nexport default Ember.Route.extend(ConfirmationMixin, {\n  shouldCheckIsPageDirty(transition) {\n    const isChildRouteTransition = this._super(...arguments);\n\n    if (transition.targetName === 'some-exempt-route') {\n      return true;\n    } else {\n      return isChildRouteTransition;\n    }\n  }\n});\n```\n\n### onUnload logic\nIf you have some custom logic you'd like to execute when your route is unloaded,\nyou can tie into the `onUnload` function. By default, this function is a no-op.\n\n```javascript\nexport default Ember.Route.extend(ConfirmationMixin, {\n  onUnload() {\n    // my custom unload logic\n  }\n});\n```\n\n# Upgrading\nThis library underwent major API changes with version 1.0.0. For information on\nhow to upgrade, please check out [UPGRADING.md](https://github.com/jasonmit/ember-onbeforeunload/blob/master/UPGRADING.md).\n\n# Issues\nFound a bug? Please report it!\n\n# Development Instructions\n\n## Installing\n* `git clone` this repository\n* `npm install`\n* `bower install`\n\n### Linting\n\n* `npm run lint:js`\n* `npm run lint:js -- --fix`\n\n### Running tests\n\n* `ember test` – Runs the test suite on the current Ember version\n* `ember test --server` – Runs the test suite in \"watch mode\"\n* `npm test` – Runs `ember try:each` to test your addon against multiple Ember versions\n\n### Running the dummy application\n\n* `ember serve`\n* Visit the dummy application at [http://localhost:4200](http://localhost:4200).\n\nFor more information on using ember-cli, visit [http://www.ember-cli.com/](http://www.ember-cli.com/).\n\n[npm]: https://www.npmjs.org/package/ember-onbeforeunload\n[npm-badge]: https://img.shields.io/npm/v/ember-onbeforeunload.svg?style=flat-square\n[travis]: https://travis-ci.org/jasonmit/ember-onbeforeunload\n[travis-badge]: https://img.shields.io/travis/jasonmit/ember-onbeforeunload.svg?branch=master\u0026style=flat-square\n","funding_links":[],"categories":["Packages"],"sub_categories":["UX"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjasonmit%2Fember-onbeforeunload","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjasonmit%2Fember-onbeforeunload","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjasonmit%2Fember-onbeforeunload/lists"}