tb-vue-hash-router

A Vue hash-router-plugin
861
Install
npm install tb-vue-hash-router
Latest Version:1.0.2
Vue:2
License:MIT
Last Updated:Dec 18, 2018
Links: npm
Maintainer: tbalint19

Vue hash router plugin (with disabled back button)

Usage

Install in your VueJS project:

npm i -s tb-vue-hash-router

Import in main.js and install it with a landing page:

import HashRouterPlugin from 'tb-vue-hash-router'

Vue.use(HashRouterPlugin, { landingPage: 'my-custom-starter-page' })

Vue.component('my-custom-starter-page', MyCustomStarterPage)

All your pages should be globally installed in main.js!

import MyCustomStarterPage from './components/my-custom-starter-page'

In your root vue component:

<template>
  <div>
    <page-root></page-root>
  </div>
</template>

And you are good to go!

API:

The default usage (with globally installed pages):

methods: {
  navigateToHome: function() {
    this.$navigate('home-page')
    // the page rendered in <page-root> is home-page.vue
    // hash is #home
    // back button still useless
  }
}

...or simply from the template:

<template>
  <div>
    <button @click="$navigate('home-page')">Home</button>
  </div>
</template>

The param of $navigate function is always a string: the name of a globally registered page.


Full API:
// simple redirect without params
this.$navigate('home-page')

// simple redirect with params - available in next page with $getRedirectParams
this.$navigate('home-page', { someKey: "someValue" })
// loads the redirect params (most likely in created() lifecycle method)
/*
  in a page loaded with #products?id=5
  the object { id: 5 } is available
  with $getRedirectParams
*/
let params = this.$getRedirectParams()
// adds ?id=5 to the hash
this.$addToQueryParams("id", 5)

// deletes query param id if exists
this.$deleteQueryParam("id")

// deletes all query params
this.$deleteQueryParams()

// updates multiple params to the hash: ?id=5&show=false
// previous params deleted
this.$updateQueryParams({ id: 5, show: false })

Related Packages

pinia-plugin-router

A pinia plugin that help use vue-router in pinia

4,356
@styzy/vue-tab-router

A Tab Router Plugins For Vue.js

948 8
vue-h-router

Small router for Vue.js 2 with hash navigation support

623 1
vue-link-interceptor

Vue 3 plugin to intercept all tag clicks in your SPA — handle internal routing a...

5,447 0
vue-2-crumbs

Breadcrumbs plugin for Vue.js 2 framework that allows to select parent route in...

3,891 35

Version History

Version Released Vue License
1.0.2 ^2.5.2 MIT
1.0.1 ^2.5.2 MIT
1.0.0 ^2.5.2 MIT
0.0.25 ^2.5.2 MIT
0.0.24 ^2.5.2 MIT