Skip to content

Custom module name #37

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 14, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ sync(store, router) // done.
// bootstrap your app...
```

You can set a custom vuex module name

```js
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:
Expand Down
10 changes: 6 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
exports.sync = function (store, router) {
store.registerModule('route', {
exports.sync = function (store, router, options) {
var moduleName = (options || {}).moduleName || 'route'

store.registerModule(moduleName, {
state: {},
mutations: {
'router/ROUTE_CHANGED': function (state, transition) {
store.state.route = Object.freeze({
store.state[moduleName] = Object.freeze({
name: transition.to.name,
path: transition.to.path,
hash: transition.to.hash,
Expand All @@ -22,7 +24,7 @@ exports.sync = function (store, router) {

// sync router on store change
store.watch(
function (state) { return state.route },
function (state) { return state[moduleName] },
function (route) {
if (route.fullPath === currentPath) {
return
Expand Down