@b12k/vue3-router-gmc
Vue 3 Router - Get Matched Components
List components that are going to enter, leave or stay on the page after navigation
Installation
npm
npm i @b12k/vue3-router-gmc
yarn
yarn add @b12k/vue3-router-gmc
pnpm
pnpm add @b12k/vue3-router-gmc
Usage
import { getMatchedComponents } from '@b12k/vue3-router-gmc';
import { createRouter } from 'vue-router';
const router = createRouter({/* routes */});
router.beforeEach(async (to, from) => {
const {
entering, // array of components entering the page
leaving, // array of components leaving the page
staying, // array of components staying on the page
} = await getMatchedComponents(to, from);
});
💡 Also works with beforeResolve guard.
Real world example
This lib is used in The Boilerplate Vue 👉 HERE
Behavior
Only components of matched route records and named views are returned. Local component registrations are not traversed. Components are compared by definition identity; using the same definition on both routes reports it as staying.
Lazy loaders may return a component directly or a module with a default export. Successful loads are cached on the route record, so Vue Router uses the same component without loading it again. Concurrent calls share pending loads within the same record and named view. Failed loads propagate their error and can be retried.
Functional components must have a displayName or props property, as required
by Vue Router to distinguish them from lazy loaders.
Development
Use Node.js 26 (.nvmrc) and the pnpm version pinned in packageManager.
The package targets the current Vue and Vue Router major versions and ships ESM and CommonJS.
pnpm devwatches the library and declarations with Rslib.pnpm buildcreates ESM and CJS bundles with separate declarations with Rslib.pnpm testruns Rstest regression tests, including real Vue Router integration.pnpm test:typeschecks the built public declarations for both import and require.pnpm lintchecks types, type-aware Oxlint rules, and Oxfmt formatting.
Version History
| Version | Released | Vue | License |
|---|---|---|---|
| 0.2.1 | ^3.5.43 | MIT | |
| 0.2.0 | ^3.5.43 | MIT | |
| 0.1.3 | >=3 | MIT | |
| 0.1.2 | >=3 | MIT | |
| 0.1.1 | >=3 | MIT | |
| 0.1.0 | >=3 | MIT | |
| 0.0.2 | >=3 | MIT | |
| 0.0.1 | >=3 | MIT |