Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
V

vuex-router-sync

> 前端框架
Open source

Effortlessly keep vue-router and vuex store in sync.

2.5K stars0 likes2 views
WebsiteGitHub

About

Effortlessly keep vue-router and vuex store in sync.

Vuex Router Sync

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

中文版本 (Chinese Version)

Usage

bash
# 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
javascript
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:

javascript
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:

    javascript
    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

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

JavaScriptvuevue-routervuex

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category前端框架
PricingOpen source

> Related tools

R
React
用于构建用户界面的 JavaScript 库
V
Vue.js
渐进式 JavaScript 框架
N
Next.js
基于 React 的全栈 Web 框架