Search code examples
vue.jsnativescriptvuexnativescript-vue

How to use $navigateTo in natviescript-vue vuex store actions?


this.$navigateTo works perfectly fine within the methods of my components, but inside a mutation neither of Vue.$navigateTo and this.$navigateTo work. My navigation depends on the result I get from an api call, if there is no way to perform a navigation from within store actions, how can I get some return value from an store action so I can perform my navigation within my component?


Solution

  • You can return a value from a store action. Since actions are async, you will need to handle the resulting promise, doing something like

    store.dispatch('actionA').then((target) => {
      // navigate to target
    })
    

    The concept is explained here: https://vuex.vuejs.org/guide/actions.html#composing-actions