vuex-router-sync

WebJar for vuex-router-sync

License

License

MIT
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

vuex-router-sync
Last Version

Last Version

4.1.3
Release Date

Release Date

Type

Type

jar
Description

Description

vuex-router-sync
WebJar for vuex-router-sync
Project URL

Project URL

https://www.webjars.org
Source Code Management

Source Code Management

https://github.com/vuejs/vuex-router-sync

Download vuex-router-sync

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.npm/vuex-router-sync/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>vuex-router-sync</artifactId>
    <version>4.1.3</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/vuex-router-sync/
implementation 'org.webjars.npm:vuex-router-sync:4.1.3'
// https://jarcasting.com/artifacts/org.webjars.npm/vuex-router-sync/
implementation ("org.webjars.npm:vuex-router-sync:4.1.3")
'org.webjars.npm:vuex-router-sync:jar:4.1.3'
<dependency org="org.webjars.npm" name="vuex-router-sync" rev="4.1.3">
  <artifact name="vuex-router-sync" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='vuex-router-sync', version='4.1.3')
)
libraryDependencies += "org.webjars.npm" % "vuex-router-sync" % "4.1.3"
[org.webjars.npm/vuex-router-sync "4.1.3"]

Dependencies

There are no dependencies for this project. It is a standalone project that does not depend on any other jars.

Project Modules

There are no modules declared in this project.

vuex-router-sync Build Status

中文版本 (Chinese Version)

Sync vue-router's current $route as part of vuex store's state.

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

org.webjars.npm

vuejs

Versions

Version
4.1.3