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
    1. Home
    2. vildar
    V
    • Profile
    • Following 0
    • Followers 0
    • Topics 0
    • Posts 1
    • Best 0
    • Groups 0

    vildar

    @vildar

    0
    Reputation
    7
    Profile views
    1
    Posts
    0
    Followers
    0
    Following
    Joined Last Online

    vildar Follow

    Latest posts made by vildar

    • RE: Store is no longer accessible in router.

      @matzeso I came to this topc with the exact problem and my “solution” looked like yours, so I think it’s relevant here. I’ve now a solution which is somewhat a workaround but still playing by the rules. I use route meta fields in routes.js and markup any route that should have my auth guard with requiredAuth meta field.

      const routes = [
        {
          path: '/home',
          component: () => import('layouts/BaseLayout.vue'),
          children: [
            { path: '',
              name: 'pagename',
              meta: { requireAuth: true },
              component: () => import('pages/HomePageName.vue') }
          ]
        }
      ]
      

      In router/index.js I then I pass store as an argument in the export default function and implement a beforeEach that checks the meta field. So the guard that require access to the store and a getter, is moved into a beforeEach function. It’s not strictly the same but good enough for me.

      export default function ({ store }) {
        const Router = new VueRouter({
        ...
        })
      
        Router.beforeEach((to, from, next) => {
          if (to.matched.some(record => record.meta.requireAuth)) {
            if (store.getters['auth/isSignedIn']) {
              next()
            } else {
              next({ name: 'account-signin', query: { next: to.fullPath } })
            }
          } else {
            next()
          }
        })
      
        return Router
      }
      

      So a little mix of previous replies by @metalsadman and others, with other parts of vue-router made it work for me.

      posted in Framework
      V
      vildar