I see in this pull request:
Add a
router.reload()
Reload with current path and call data hook again
But when I try issuing the following command from a Vue component:
this.$router.reload()
I get this error:
Uncaught TypeError: this.$router.reload is not a function
I searched in the docs, but could not found anything relevant. Does vue/vue-router provider some functionality like this?
The software versions I'm interested in are:
"vue": "^2.1.0",
"vue-router": "^2.0.3",
PS. I know location.reload()
is one of the alternatives, but I'm looking for a native Vue option.
Best Answer
this.$router.go()
does exactly this; if no arguments are specified, the router navigates to current location, refreshing the page.As to 'why is it so':
go
internally passes its arguments towindow.history.go
, so its equal towindows.history.go()
- which, in turn, reloads the page, as per MDN doc.