No More Posting New Topics!

If you have a question or an issue, please start a thread in our Github Discussions Forum.
This forum is closed for new threads/ topics.

Navigation

    Quasar Framework

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    vuex-router-sync

    Help
    3
    4
    1374
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • J
      John last edited by

      The migration guide lists various use cases for app plugins, among them the usage of vuex-router-sync:

      You want to interfere with the Vuex store instance - An example would be to use vuex-router-sync package

      So that’s what I want to do, but I must miss something, because I can’t figure out how. First I installed the package ‘vuex-router-sync’ from here.

      https://github.com/vuejs/vuex-router-sync

      Then I created an app plugin called ‘router.js’ like this

      // import something here
      import { sync } from 'vuex-router-sync'
      
      // leave the export, even if you don't use it
      export default ({ app, router, store, Vue }) => {
       // setup sync
       const unsync = sync(store, router)
      }
      

      and registered the plugin in quasar.conf.js. The default function is called, I checked this. However, I cannot access the route from the state property in the store so it doesn’t get extended. What am I missing?

      Greetings,
      John

      1 Reply Last reply Reply Quote 0
      • J
        John last edited by

        Okay got it. If you read the vuex documentation (https://vuex.vuejs.org/en/modules.html) carefully, not like I did, then you will find out that the ‘rootState’ is always passed on as third argument:

        Also, inside module getters, the root state will be exposed as their 3rd argument…

        This will allow you to access the route plugin and state.

        1 Reply Last reply Reply Quote 2
        • E
          Evertvdw last edited by

          Hello there, I’m having trouble getting this to work and I don’t know why. I’m using quasar v1 and have a boot file that is being called (I checked) with the code above. However when I inspect the rootState object available in an action in the store I don’t have any route property. Anyone any ideas?

          1 Reply Last reply Reply Quote 0
          • Q
            quang last edited by

            As of 5-26-2020, this works for me, boot file name router.js, not using vuex modules.

            import { sync } from 'vuex-router-sync';
            import { boot } from 'quasar/wrappers';
            
            export default boot(({ router, store }) => {
              sync(store, router);
            });
            
            1 Reply Last reply Reply Quote 0
            • First post
              Last post