Vue-router: Router's $route object not updating on query strings alone

Created on 21 Oct 2016  路  7Comments  路  Source: vuejs/vue-router

Versions

vue 2.0.3
vue-router 2.0.1
vuex: 2.0.0
vuex-router-sync: 3.0.0

Issue

I am using $router.push to update a paginated list page, therefore have the following code:

changePage(page) { let data = this.$route.query; data['page'] = page; this.$router.push({ path : '/list', query: data }); }

This I would have imagined would trigger an update in:

watch: { $route() { console.log('updated route'); } }

However this does not.
On researching I noticed that after triggering this.$route.push), console logging $route.params.query.page shows it has actually updated, however what is not updating is $route.fullPath and I'm guessing the watcher is looking for changes in this property.

Can you confirm whether this is bug, or how it is actually supposed to work?

Thanks

Most helpful comment

isn't <router-link> supposed to handle this sort of change? I'm having same problem for pagination where /?page=1 and /?page=2 links aren't updating the component.

<router-link :to="{ name: 'home', query: { page: page }}">{{page}}</router-link>

All 7 comments

Just to add/reiterate, $route.fullPath does update when pushing changes where params are updated, for example. going from / to /list, it works fine. The problem lies only when trying to update query strings.

Hi, thanks for filling this issue. Please follow the Issue Reporting Guidelines and provide a live reproduction on jsfiddle, codepen etc. Thanks!

@fnlctrl, apologies!

Example: Fiddle

You're directly mutating $route, which doesn't trigger a transition. Please copy the object instead : https://jsfiddle.net/fnlCtrl/gd6rvxt7/

isn't <router-link> supposed to handle this sort of change? I'm having same problem for pagination where /?page=1 and /?page=2 links aren't updating the component.

<router-link :to="{ name: 'home', query: { page: page }}">{{page}}</router-link>

I just tried making a copy of the object, and it didn't work for me...do you have any other suggestions?

I have the same issue with
router-link(class="pure-menu-link" :to="prev_link")
and
prev_link() { return { name: 'index', query: {page: parseInt(this.pageIndex) - 1} } },

Was this page helpful?
0 / 5 - 0 ratings