0👍
In the component you want to set multiple redirects based on a condition you can use beforeRouteEnter()
property in that component like below:
beforeRouteEnter(to,from,next){
next(vm => {
if(condition 1){
vm.$router.push('the path you want to redirect');
}else if(condition 2){
vm.$router.push('the path you want to redirect');
}else{
//no redirect
next();
}
});
}
Since the vue instance is not yet created when beforeRouteEnter()
property is called you cannot use this
to access the vue instance and follow the process the method shown above via vm
Another way would be by using route meta feilds where you would include a meta field when defining a route and checking for a meta field in the global navigation guard. In that global navigation guard you can redirect by checking various if
statements.
Source:stackexchange.com