Skip to content

How to use nprogress package to show a loading top-bar on Vike? #1611

Discussion options

You must be logged in to vote

Hi @Blankeos,
First, you need to install nprogress. Run npm install nprogress or pnpm add nprogress. Additionally, if you are using TypeScript, install the types with npm install -D @types/nprogress or pnpm add -D @types/nprogress.
Next, import the CSS by adding import "nprogress/nprogress.css" inside your LayoutDefault.tsx file.

To show the top-bar loading when navigating between pages, use it with the +onPageTransitionStart and +onPageTransitionEnd hooks.

For example:

// +onPageTransitionStart.ts
import type { OnPageTransitionStartAsync } from "vike/types";
import NProgress from "nprogress"

export const onPageTransitionStart: OnPageTransitionStartAsync = async () => {
  console.log("Pa…

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
2 replies
@Blankeos
Comment options

@phonzammi
Comment options

Answer selected by Blankeos
Comment options

You must be logged in to vote
2 replies
@phonzammi
Comment options

@brillout
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants