davestewart / vuex-pathify

Vue / Vuex plugin providing a unified path syntax to Vuex stores
https://davestewart.github.io/vuex-pathify
MIT License
1.37k stars 57 forks source link

vue router navigation guard #134

Closed RyeBot33 closed 3 years ago

RyeBot33 commented 3 years ago

Have a module called app.js and the state looks something like this:

const state = { authenticated = false }

const mutations = make.mutations(state);

const getters = { ...make.getters(state) };

With a login page that has computed property setup with

...sync("app", ["authenticated"])

that I am setting with an @click="authenticated = true"

How could I set up a navigation guard in vue router to access this store property? I feel like it is simple, but not sure.

davestewart commented 3 years ago

Hi,

Sorry for the wait! I've been away from OSS for a while.

Pathify is mainly designed to clean up the store and components, so in the router you can just access the store as you would otherwise:

import store from './store'

...

router.beforeEach((to, from, next) => {
  if (!store.state.app.authenticated) {
    next(false)
  }
})

Hope that helps.