tb-vue-hash-router
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
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 | |
| 0.0.23 | ^2.5.2 | MIT | |
| 0.0.22 | ^2.5.2 | MIT | |
| 0.0.21 | ^2.5.2 | MIT | |
| 0.0.20 | ^2.5.2 | MIT | |
| 0.0.19 | ^2.5.2 | MIT | |
| 0.0.18 | ^2.5.2 | MIT | |
| 0.0.17 | ^2.5.2 | MIT | |
| 0.0.16 | ^2.5.2 | MIT | |
| 0.0.15 | ^2.5.2 | MIT | |
| 0.0.14 | ^2.5.2 | MIT | |
| 0.0.13 | ^2.5.2 | MIT | |
| 0.0.12 | ^2.5.2 | MIT | |
| 0.0.11 | ^2.5.2 | MIT | |
| 0.0.10 | ^2.5.2 | MIT | |
| 0.0.9 | ^2.5.2 | MIT | |
| 0.0.8 | ^2.5.2 | MIT | |
| 0.0.7 | ^2.5.2 | MIT | |
| 0.0.6 | ^2.5.2 | MIT | |
| 0.0.5 | ^2.5.2 | MIT | |
| 0.0.4 | ^2.5.2 | MIT | |
| 0.0.3 | ^2.5.2 | MIT | |
| 0.0.2 | ^2.5.2 | MIT | |
| 0.0.1 | ^2.5.2 | MIT |