Skip to content

Commit 0353997

Browse files
committed
Kill previously keepAlive page instance
1 parent 92d2d9a commit 0353997

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-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: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,12 @@ export let routes = new Map()
122122
*/
123123
export let components = new Map()
124124

125+
/**
126+
* Copy of components created at boot time
127+
* @type {Map<string, object>}
128+
*/
129+
export let bootcomponents = new Map()
130+
125131
/**
126132
* Flag if router has been initialised
127133
* @type {boolean}
@@ -218,6 +224,7 @@ const setup = config => {
218224
pagesHost.a(type)
219225
}
220226
}
227+
bootcomponents.set(path, type)
221228
components.set(path, type)
222229
}
223230
} else {
@@ -299,6 +306,14 @@ export const getComponent = route => {
299306
}
300307
return null
301308
}
309+
310+
// repace the current with boot instance
311+
export const deleteCurrentInstance = route => {
312+
if(bootcomponents.has(route)){
313+
components.set(route, bootcomponents.get(route))
314+
}
315+
}
316+
302317
/**
303318
* Test if router needs to update browser location hash
304319
* @returns {boolean}

0 commit comments

Comments
 (0)