Is it possible to load one of three potential routes based on a user's role in my pinia store? The issue I'm currently facing is that the pinia store doesn't appear to be initialized before the router is set, resulting in the error
Uncaught Error: [🍍]: getActivePinia was called with no active
How can I resolve this problem?
Just as a point of reference, here are how the routes are defined:
const roleOneRoutes = [
{
path: '/home',
name: 'home',
component: () => import('@/pages/RoleOne/Home'),
},
...
]
const roleTwoRoutes = [
{
path: '/home',
name: 'home',
component: () => import('@/pages/RoleTwo/Home'),
},
...
]
Ideally, I would like something similar to the following in the index file:
const { user } = useAuthStore()
const mappedRoutes = user.role === 'roleOne' ? roleOneRoutes : roleTwoRoutes
export const router = createRouter({
history: createWebHistory(),
routes: mappedRoutes
})