Skip to content

Commit f29fe4a

Browse files
committed
update route mutation
1 parent 0a96b95 commit f29fe4a

File tree

2 files changed

+2
-11
lines changed

2 files changed

+2
-11
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ sync(store, router) // done.
3131

3232
- When the router navigates to a new route, the store's state is updated.
3333

34-
- When the store's `route` state is updated, it notifies the router to navigate to the corresponding path. This enables time-traveling between routes in `vue-devtools`.
34+
- **`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.go()`.
3535

3636
### License
3737

index.js

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,7 @@ function patchStore (store) {
4949
route: {
5050
mutations: {
5151
'router/ROUTE_CHANGED': function (state, to) {
52-
Object.keys(to).forEach(key => {
53-
if (key !== 'matched') {
54-
set(state, key, to[key])
55-
}
56-
})
57-
Object.keys(state).forEach(key => {
58-
if (!(key in to)) {
59-
state[key] = null
60-
}
61-
})
52+
store.state.route = to
6253
}
6354
}
6455
}

0 commit comments

Comments
 (0)