1.0.2 • Published 7 years ago

tb-vue-hash-router v1.0.2

Weekly downloads
1
License
MIT
Repository
-
Last release
7 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

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago

0.0.25

7 years ago

0.0.24

7 years ago

0.0.23

7 years ago

0.0.22

7 years ago

0.0.21

7 years ago

0.0.20

7 years ago

0.0.19

7 years ago

0.0.18

7 years ago

0.0.17

7 years ago

0.0.16

7 years ago

0.0.15

7 years ago

0.0.14

7 years ago

0.0.13

7 years ago

0.0.12

7 years ago

0.0.11

7 years ago

0.0.10

7 years ago

0.0.9

7 years ago

0.0.8

7 years ago

0.0.7

7 years ago

0.0.6

7 years ago

0.0.5

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago