GitXplorerGitXplorer
v

vuex-router-sync

public
2516 stars
125 forks
11 issues

Commits

List of commits on branch master.
Unverified
f8088e289f317a378b5d737edbd1bfe07f3d3e8d

ci: add github actions integration

kkiaking committed 4 years ago
Unverified
3b16c68a1145f97d1a4c4309eef7f5f0a17c1cd9

chore: generate html coverage report

kkiaking committed 4 years ago
Unverified
b803df31def47f83a1173e60b187be55eefcc569

chore: ignore coverage directory

kkiaking committed 4 years ago
Unverified
19d26ef152970a94a681c4876a557033fe748844

chore: remove unused script

kkiaking committed 4 years ago
Unverified
b8f6603bd5413d865bdb6995eb084de9f2315991

build: update npm packages

kkiaking committed 4 years ago
Unverified
795c8db6d2206ba26468a558fd66007680bf79e4

chore: fix package version

kkiaking committed 4 years ago

README

The README file for this repository.

Vuex Router Sync

npm ci status coverage license

Sync Vue Router's current $route as part of Vuex store's state.

中文版本 (Chinese Version)

Usage

# the latest version works only with vue-router >= 2.0
npm install vuex-router-sync

# for usage with vue-router < 2.0:
npm install vuex-router-sync@2
import { sync } from 'vuex-router-sync'
import store from './store' // vuex store instance
import router from './router' // vue-router instance

const unsync = sync(store, router) // done. Returns an unsync callback fn

// bootstrap your app...

// During app/Vue teardown (e.g., you only use Vue.js in a portion of your app
// and you navigate away from that portion and want to release/destroy
// Vue components/resources)
unsync() // Unsyncs store from router

You can optionally set a custom vuex module name:

sync(store, router, { moduleName: 'RouteModule' } )

How does it work?

  • It adds a route module into the store, which contains the state representing the current route:

    store.state.route.path   // current path (string)
    store.state.route.params // current params (object)
    store.state.route.query  // current query (object)
  • When the router navigates to a new route, the store's state is updated.

  • store.state.route is immutable, because it is derived state from the URL, which is the source of truth. You should not attempt to trigger navigations by mutating the route object. Instead, just call $router.push() or $router.go(). Note that you can do $router.push({ query: {...}}) to update the query string on the current path.

License

MIT