Reputation: 112
HI all I am trying to import my store into my Vuex Route-Gard.
router/auth-guard.js
import {store} from '../store'
export default (to, from, next) => {
if (store.getters.user) {
next()
} else {
next('/login')
}
}
store/index.js
import {store} from '../store'
export default (to, from, next) => {
if (store.getters.user) {
next()
} else {
next('/login')
}
}
The error I am getting export 'store' was not found in '../store'
my vue set up
"dependencies": {
"firebase": "^4.3.0",
"vue": "^2.3.3",
"vue-router": "^2.6.0",
"vuex": "^2.3.1"
Upvotes: 4
Views: 10141
Reputation: 112
I was able to resolve this, through this method.
main.js
import {store} from './store'
new Vue({
el: '#app',
router,
store,
template: '<App/>',
components: {
App
},
auth-guard.js
import {store} from '../store'
export default (to, from, next) => {
if (store.getters.user) {
next()
} else {
next('/login')
}
}
store/index.js
Vue.use(Vuex)
export const store = new Vuex.Store({
modules: {
products,
bids,
user
}
})
Upvotes: 2