How it works
A hybrid built on a single shared bar instance — there is never more than one bar on screen:- Automatic (router-driven). The router shows the bar during navigation, most visibly on the web where visiting a route for the first time downloads its lazy-loaded chunk. Every page gets this for free; static pages need no code.
- Opt-in (page-driven). A page that fetches its own data drives the same bar through the fetch, so the bar reflects the real load — not just the navigation.
- Trickle:
start()shows the bar and lets it creep toward 90% on its own, easing out as it goes;done()finishes it to 100% and hides it. It looks alive even when the duration is unknown, and never sits at a dead 0%. - Show-delay (200 ms): navigations faster than this never flash the bar. On native builds route chunks are bundled, so navigation is instant and the router bar simply doesn’t appear — only real data-loading pages show a bar there.
- Accessibility: honors
prefers-reduced-motion— the fill’s slide transition and the animated stream dots switch off.
Files
Quick start: nothing to do
For a normal page that just renders (no data fetch on entry), do nothing — the router-driven bar already covers it. This is every static page in the kit (Home, Account, Settings, etc.).Adding a data-loading page
1
Mark the route
In
src/router/routes.ts, so the router hands the bar to the page instead of completing it on arrival:2
Drive it — always complete in a finally
3
(Optional) multi-step
Call
set() between stages for a determinate bar (this stops the auto-trickle and puts you in control):Driving the bar from an action
The same instance can visualize a multi-step action on the current page — e.g. the sign-in flow insrc/views/pages/_base/Login.vue:
set() (not start()) here when you want explicit, meaningful percentages rather than an
automatic trickle.
API
useRouteProgress() — the global bar
Used 99% of the time. All calls target the same shared instance.
useSharedPageProgress(key) — low-level, keyed
Returns { progress, buffer, start, set, done } for an independent instance identified by key.
No trickle (its start() just sets 0 / 0.1). Use it only when you need a bar that is not
the global one (see Advanced).
useCombinedPageProgress(...keys)
Returns read-only { progress, buffer } where progress is the minimum of all sources — a single
bar that waits for several keyed sources to finish.
Best practices
- Always
done()in afinally. If the fetch throws and you don’t complete, the bar stays visible. Thetry/finallypattern above guarantees completion. - Don’t mark static pages
managesProgress. If you set the flag but never calldone(), the router won’t complete the bar for you and it hangs. Only add the flag together with thestart()/done()wiring. - Prefer the global bar. Reach for
useSharedPageProgresswith a custom key only for a genuinely separate bar (e.g. inside a modal). Two global-position bars would overlap. start()vsset():start()= “I don’t know how long, show activity” (auto-trickle);set()= “I know the real percentage”.- In-content spinners are optional. Some kit pages also show a centered
ion-spinnerduring load. Keep it, or remove it and rely on the bar alone — your call. - Keep the buffer below 1 for the moving dots. Ionic only shows the animated stream when
buffer < 1. The trickle andset()defaults already do this.
Advanced: an independent bar
For a bar that must be separate from the global one — for example inside a modal that loads its own content — use a keyed instance and render your own bar:Customization
All inuseRouteProgress.ts, PageProgressBar.vue and styles/components/page-progress-bar.scss:
Gotchas & edge cases
- Single shared instance. Because there is exactly one bar, a page that navigates away
before its own fetch resolves and then calls
done()late can briefly hide a bar that the next page had already started. This is cosmetic (the bar just vanishes a little early — never a stuck or wrong state) and is the accepted trade-off of the single-bar model. Fetches that resolve while the page is still on screen are unaffected. - Native = usually no router bar. Bundled chunks make navigation instant, so the router bar stays hidden; only real data-loading pages show a bar. This is intentional (no fake progress).
- Reduced motion. Under
prefers-reduced-motionthe fill transition and stream dots are disabled; the value still updates, just without the decorative animation. - Guard order.
installRouteProgressis registered after the app’s auth/redirect guards and never blocks or alters navigation — it only observes it.
Testing tips
-
Type-check:
npx vue-tsc --noEmit(also part ofnpm run build). -
See it locally: dev navigations are fast, so throttle the network (DevTools → Network →
Slow 3G) and navigate to a lazy route to watch the router bar; or visit a data page
(
/subscription,/support) to watch a page-driven bar. -
Drive it from the console (dev server) to inspect states without a real load: