Skip to content

Commit

Permalink
Be defensive about unmounting uiRouter. Resolves #59.
Browse files Browse the repository at this point in the history
  • Loading branch information
joeldenning committed Mar 18, 2021
1 parent 03d49e9 commit 24dcfb2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
4 changes: 3 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
.prettierignore
LICENSE
yarn.lock
.npmignore
.npmignore
lib
pnpm-lock.yaml
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "the logic needed to register angular 1 apps with single-spa",
"main": "lib/single-spa-angularjs.js",
"scripts": {
"format": "prettier './**/*' --write",
"format": "prettier . --write",
"build": "rimraf lib && babel src --out-dir lib --source-maps",
"prepublishOnly": "yarn build"
},
Expand Down
14 changes: 10 additions & 4 deletions src/single-spa-angularjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,16 @@ function mount(opts, mountedInstances, props = {}) {

function unmount(opts, mountedInstances, props = {}) {
return new Promise((resolve, reject) => {
// https://github.com/single-spa/single-spa-angularjs/issues/53
const uiRouter = mountedInstances.instance.get("$uiRouter");
if (uiRouter) {
uiRouter.dispose();
if (mountedInstances.instance.has("$uiRouter")) {
// https://github.com/single-spa/single-spa-angularjs/issues/53
const uiRouter = mountedInstances.instance.get("$uiRouter");
if (uiRouter.dispose) {
uiRouter.dispose();
} else {
console.warn(
"single-spa-angularjs: the uiRouter instance doesn't have a dispose method and so it will not be properly unmounted."
);
}
}

mountedInstances.instance.get("$rootScope").$destroy();
Expand Down

0 comments on commit 24dcfb2

Please sign in to comment.