Skip to content

Commit 4da6331

Browse files
authored
Merge pull request #390 from jay-patel9/master
Kill previously keepAlive page instance
2 parents 18fc9ed + 2267d34 commit 4da6331

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

src/Router/index.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -804,6 +804,11 @@ declare namespace Router {
804804
*/
805805
export function getActivePage(): Lightning.Component | null;
806806

807+
/**
808+
* Returns the reference of the active Page instance
809+
*/
810+
export function deletePage(param: string): void;
811+
807812
/**
808813
* Returns the active route path blueprint
809814
*/

src/Router/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import {
4444
beforeEachRoute,
4545
getActiveHash,
4646
getActiveRoute,
47+
deleteCurrentInstance,
4748
} from './utils/router'
4849

4950
import { focusWidget, getActiveWidget, restoreFocus } from './utils/widgets'
@@ -517,6 +518,10 @@ const root = () => {
517518
}
518519
}
519520

521+
const deletePage = (param) => {
522+
deleteCurrentInstance(param)
523+
}
524+
520525
// export API
521526
export default {
522527
startRouter,
@@ -530,6 +535,7 @@ export default {
530535
// warning
531536
return getActivePage()
532537
},
538+
deletePage,
533539
getActiveRoute,
534540
getActiveHash,
535541
focusWidget,

src/Router/utils/router.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,15 @@ export const getComponent = route => {
299299
}
300300
return null
301301
}
302+
303+
// delete existing route instance from memory
304+
export const deleteCurrentInstance = route => {
305+
if (components.has(route) && pagesHost.getIndex(components.get(route)) !== -1) {
306+
pagesHost.remove(components.get(route))
307+
storeComponent(route, components.get(route)._routedType || components.get(route).constructor)
308+
}
309+
}
310+
302311
/**
303312
* Test if router needs to update browser location hash
304313
* @returns {boolean}

0 commit comments

Comments
 (0)