refreshApp
Type:
FunctionParameters:
startOptions(same as startApp)Returns:
Promise<Function | void>
Programmatically refreshes a sub-app: first calls destroyApp to destroy the current instance, then calls startApp with the provided options to perform a full rebuild. Internally it awaits destroyApp before invoking startApp, preventing race conditions caused by restarting before teardown finishes.
This is equivalent to chaining destroyApp(name) + startApp(startOptions) with framework-guaranteed sequencing.
Use Cases
- The sub-app runs in Rebuild Mode and you want to force a full rebuild to reset state and reload assets.
- Sub-app code or static assets have been updated and you need to discard the old instance and re-fetch.
- When using Vue or React wrapper components, you can also call refresh() via the component ref with no arguments to rebuild using the component's current props.
Note
- Refreshing destroys the current sub-app instance along with its
iframeandshadowRoot, which may cause a brief blank screen during reload. - Options such as
name,replace,fetch,alive, anddegrademust remain consistent with the initialstartAppcall to avoid rendering issues. - Avoid refreshing unnecessarily if the sub-app will be revisited normally; use
refreshApponly when a full rebuild is required.
Example
javascript
import { refreshApp } from "wujie";
await refreshApp({
name: "vue3",
url: "https://xxx.com/",
el: document.querySelector("#container"),
});
When using the Vue or React wrapper components:
javascript
// Static method refreshApp (same options as startApp)
import WujieVue from "wujie-vue3";
await WujieVue.refreshApp({ name: "vue3", url: "...", el: "..." });
// Component instance method refresh() — no arguments needed, reuses current component props
await this.$refs.wujie.refresh();
