Quasar: [docs] this.$router.push -> uncaught exception: Object -> how to solve

Created on 21 Nov 2019  路  4Comments  路  Source: quasarframework/quasar

may for the docs or anybody else, who is also facing those uncaught exception error

since vue-router v. 3.1.0 there are some nasty uncaught exceptions inside my console
log, when clicking / programmatic change / push a route (and fetching a duplicate route)
with:

this.$router.push('/location')

to get rid of those logs, the programmtic change should be syntaxed now like
this:

this.$router.push('/location', () => { })

alternatively you can also catch a possible error, when it failes:

router.push('/location').catch(err => {})

More Details:
https://github.com/vuejs/vue-router/issues/2881#issuecomment-520554378

docs

Most helpful comment

@rstoenescu Yes, totally, that potentially hides all errors though, which I don't like to do. I'd rather handle errors explicitly one by one and only ignore those that I know can be ignored safely.

All 4 comments

closed by self , made docs improvement issue request direct on the vendor git

This seems to only happen when you try to go to the route you're already on, for instance this.$router.push('/') if you're already on the homepage. If you want to keep errors, you might want to do this:

const newRoutePath = "/";
if (this.$route.path !== newRoutePath) {
  this.$router.push(newRoutePath);
}

@conradkleinespel
this.$router.push(...) returns a Promise for which you can catch such error. No need to check current route.

this.$router.push('/my-route')
  .catch(() => {})

@rstoenescu Yes, totally, that potentially hides all errors though, which I don't like to do. I'd rather handle errors explicitly one by one and only ignore those that I know can be ignored safely.

Was this page helpful?
0 / 5 - 0 ratings