npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

use-back-button

v1.0.0

Published

A Vue 3 composable to track back navigation in SPAs using Vue Router

Downloads

1

Readme

useBackButton

A lightweight Vue 3 composable for tracking navigation history in Single Page Applications using Vue Router. It provides a reliable way to show or hide a "back" button depending on whether the user can actually go back — even when they use the browser's back button or mobile gestures.


Installation

If you're using this inside your own app, just copy useBackButton.js into your src/composables/ directory.

If you plan to publish it as a package:

npm install use-back-button
# or
pnpm add use-back-button

Usage

1. Register navigation tracking in your root component (e.g. App.vue)

<script setup>
import { useBackButton } from '@/composables/useBackButton' // or from 'use-back-button' if installed via npm

useBackButton().trackNavigation()
</script>

This ensures your navigation stack is tracked across the entire app.


2. Use it in any component to show a back button

<template>
  <v-btn icon @click="goBack" v-if="canGoBack">
    <v-icon>mdi-arrow-left</v-icon>
  </v-btn>
</template>

<script setup>
import { useBackButton } from '@/composables/useBackButton'

const { canGoBack, goBack } = useBackButton()
</script>

3. Go back multiple steps

You can go back more than one route by using goBackBy(n):

goBackBy(2) // Goes back two routes in history

Before calling it, you can check if it's safe:

if (canGoBackBy(2)) {
  goBackBy(2)
}

These methods ensure your internal stack and browser history stay in sync.


What It Does

  • Tracks your app's route transitions
  • Detects if the user navigated with push, replace, or browser back
  • Lets you conditionally show back buttons only when it makes sense
  • Handles router.back() and browser/mobile back gestures cleanly

Internals

  • Uses ref() and computed() to track a reactive stack
  • Uses router.beforeEach() to monitor transitions
  • Inspects window.history.state to tell if the user navigated backward

Caveats

  • Assumes you are using Vue Router 4+ (Vue 3 only)
  • Must be initialized once at app startup using trackNavigation()

License

GPL V.3


Author

Made by Tony Mobily with irritation at bad back buttons and too many open browser tabs.