Within my routes configuration, I have a named view route set up:
let routes = [
{
name: "home",
path: '/',
components: {
default: Home,
project: ProjectIndex
}
}
]
The goal is to secure access to the "project" route based on user roles, while ensuring the default Home route remains accessible to all users.
To achieve this, I am implementing the following code snippet within the ProjectIndex component:
beforeRouteEnter (to, from, next) {
var user = Spark.state.user;
if(user.current_role == 'admin' || user.current_role == 'owner'){
next();
}
}
An issue arises as this logic is being applied not only to the ProjectIndex component but also affecting the Home component unintentionally.
This situation has made me realize that achieving such basic functionality in Vue js should ideally be simpler.
Upon calling console.log(to)
, I receive information about the route but no indication of which Component will be rendered. This obstacle has led me to seek assistance. Kindly provide guidance.