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.
Notes:
#
must have some value after it.setTimeout
, not$nextTick
to keep the url clean.router.js
main.js
It's my reload. Because of some browser very weird.
location.reload
can't reload.The simplest solution is to add a :key attribute to :
This is because Vue Router does not notice any change if the same component is being addressed. With the key, any change to the path will trigger a reload of the component with the new data.
Use
router.go(0)
if you use Typescript, and it's asking arguments for the go method.I check vue-router repo on GitHub and it seems that there isn't
reload()
method any more. But in the same file there is :currentRoute
object.Source: vue-router/src/index.js
Docs: docs
Now you can use
this.$router.go(this.$router.currentRoute)
for reload current route.Simple example.
Version for this answer: