1.0.2 • Published 5 years ago

tb-vue-hash-router v1.0.2

Weekly downloads
1
License
MIT
Repository
-
Last release
5 years ago

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 })
1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago

0.0.25

5 years ago

0.0.24

5 years ago

0.0.23

5 years ago

0.0.22

5 years ago

0.0.21

5 years ago

0.0.20

5 years ago

0.0.19

5 years ago

0.0.18

5 years ago

0.0.17

5 years ago

0.0.16

5 years ago

0.0.15

5 years ago

0.0.14

5 years ago

0.0.13

5 years ago

0.0.12

5 years ago

0.0.11

5 years ago

0.0.10

5 years ago

0.0.9

5 years ago

0.0.8

5 years ago

0.0.7

5 years ago

0.0.6

5 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago