I want to use use vue-router to route to a new component from a Vuex store. Is it possible to access the router from a Vuex store? I've seen a bunch of threads about it, but nothing that really worked for me... The error below is what I get when I try to use the router.
[Vue warn]: Error in mounted hook: "TypeError: WEBPACK_IMPORTED_MODULE_2_vue_router.a.push is not a function"
Here's my store:
SENTENCE_TRACKER({commit, state}){
let chosenSentence
if(state.currSent < state.res.length) {
chosenSentence = state.res[state.currSent];
console.log(chosenSentence);
commit('CHINESE', {chineseData:chosenSentence.chinese})
commit('ENGLISH', {englishData:chosenSentence.english})
commit('PINYIN', {pinyinData:chosenSentence.pinyin})
commit('AUDIO', {audioData:chosenSentence.audio})
commit('WBW', {wbwData:chosenSentence.wbw})
state.currSent++
} else {
// THIS IS WHERE I'D LIKE TO USE VUE-ROUTER
router.push({path:'/summary'})
}
let arr = []
state.wbw.map(function(i){
arr.push('')
})
commit('WBW_STATE', {wbwStateData: arr})
let shuffled = state.wbw.slice(), i, j, k;
for (i = shuffled.length; i; i--) {
j = Math.floor(Math.random() * i);
k = shuffled[i - 1];
shuffled[i - 1] = shuffled[j];
shuffled[j] = k;
}
commit('SHUFFLED', {shuffledData: shuffled})
},
Thanks!
router
? – Rwd