So I have this simple method in a modal:
showModal(value) {
if (value === true) {
if (this.isOpen === true) {
//do something here
}
this.showModal = true;
} else {
this.showModal = false;
router.go(-1);
// if this is the first page they visited then
// router.push('/dashboard');
}
},
this method is triggered by a click from a "go back" button. However, router.go(-1)
performs well if there are other pages clicked before this. But what if the page was the first thing they went to? Is there a way that I can check if that is the first page they went to? and redirect them to /dashboard
if it is?
You can check window.history.length
property. If it is 1, you are on the first page. Also,
const routes = [
{
path: '/',
redirect: 'dashboard'
},
...
]
is the best way to configure initial redirect with Vue Router .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.