New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@vuemod/prefetch

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@vuemod/prefetch

Easily fetch data before rendering a vue component

latest
Source
npmnpm
Version
1.1.2
Version published
Maintainers
1
Created
Source

@vuemod/prefetch logo

@vuemod/prefetch

Easily fetch data before rendering a vue component with vue-router and vuex

If you've used vue-router, vue and vuex or pinia, you are familiar with this problem.

The beforeRouteEnter guard does NOT have access to this, because the guard is called before the navigation is confirmed ...

Of course you can use:

beforeRouteEnter (to, from, next) {
  next(vm => {
    // access to component instance via `vm`
  })
}

But, if you use vuex and make a mutation, then the component will be rendered first, and then the data will appear. (The code in the next construct is executed after all hooks).

Of course, you can get data centrally in the beforeResolve hook, but then if your application grows, you will have to write a separate router ...

Plugin adds additional prefectch hook (Similar to serverPrefetch) to components, mixins, extended components and global mixins.

Installation

    yarn add @vuemod/prefetch

or

    npm i @vuemod/prefetch

Usage

In app initialization

import {createPrefetch} from "@vuemod/prefetch";

// ....
const prefetch = createPrefetch();
app.use(prefetch, router, store);

In components

export default defineComponent({
    prefetch: definePrefetch(async({
       app,  // Instance of the app
       store, // Instance of the store|pinia
       router, // Instance of the router
       isClient,  // Execute on client
       isInitial,  // Execute in initial navigation (server or client)
       isFetch // Execute in fetch mode (client and first navigation or server)
   }, to, from, next?) => { 
        // your code
    })
});

Keywords

vue

FAQs

Package last updated on 29 Mar 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts