fn
runWithApp
v0.1.0testeddemoRuns a function inside app.runWithContext, so inject (and everything built
on it) resolves app-level provides even outside of component setup — in router guards,
store actions, event handlers or timers.
The app defaults to getActiveApp(); pass one explicitly to target a specific app
(recommended for SSR, where apps are created per request).
Example
ts
router.beforeEach(() => {
const auth = runWithApp(() => inject(AuthKey));
});Demo
Loading demo…
Signature
ts
export function runWithApp<Result>(fn: () => Result, app: App | undefined = getActiveApp()): Result{ ... }Type Parameters
ResultParameters
| Parameter | Type | Description |
|---|---|---|
fn | () => Result | The function to run with the app as injection context |
app? | App | undefined | The function to run with the app as injection context |
Returns
ResultThe return value of fn