Reputation: 1668
I have two pages home
and about
. so while refreshing home
page i need to naviagate to about
page. so in home.vue
i written like this.
created () {
window.addEventListener('beforeunload', this.reloadHandler)
}
destroyed () {
window.removeEventListener('beforeunload', this.reloadHandler)
}
and in the reloadHandler
method i written router push to about
page.
reloadHandler () {
this.$nextTick(() => {
this.$router.push('/about')
})
}
Is it possible to do this with vue-router. Or is there any way to achieve it.
Upvotes: 1
Views: 3225
Reputation: 21030
Due to browser security and privacy concerns, it is not possible entirely in Vue.js/client-side. It will never be foolproof.
The best solution is to use a server-side redirect to handle this situation. When a page is refreshed, the server will receive the request. When the server gets the request from /home
route, then it should redirect to /about
using HTTP status 302
and Location
header.
Upvotes: 2