quasar icon indicating copy to clipboard operation
quasar copied to clipboard

[0.17 beta] "Cannot read property 'asyncData' of undefined" in route with no components

Open panstromek opened this issue 8 years ago • 11 comments

Going to root route / of my app throws this error

TypeError: Cannot read property 'asyncData' of undefined at eval (entry.js?cc20:99) at Array.map (<anonymous>) at eval (entry.js?cc20:98) at iterator (vue-router.esm.js?8c4f:1943) at step (vue-router.esm.js?8c4f:1717) at step (vue-router.esm.js?8c4f:1721) at step (vue-router.esm.js?8c4f:1721) at step (vue-router.esm.js?8c4f:1721) at runQueue (vue-router.esm.js?8c4f:1725) at eval (vue-router.esm.js?8c4f:1979)

other routes work well, only this one doesn't. Not sure it is related but root route redirects somewhere else, in some cases multiple times.

Quasar 0.17.0-beta.16

panstromek avatar Jul 10 '18 16:07 panstromek

I've seen this in previous beta, too but I thought it is related to something different, so sorry I didn't post it earlier

panstromek avatar Jul 10 '18 16:07 panstromek

Here is a piece of code that crashes

`

// Add router hook for handling asyncData.
// Doing it after initial route is resolved so that we don't double-fetch
// the data that we already have. Using router.beforeResolve() so that all
// async components are resolved.
router.beforeResolve((to, from, next) => {
  const asyncDataHooks = router.getMatchedComponents(to)
    .map(c => c.asyncData)  ///This is where it crashes
    .filter(_ => _)

  if (asyncDataHooks.length === 0) {
    return next()
  }


  Promise.all(
    asyncDataHooks.map(hook => hook({
      store,
      route: to
    }))
  )
  .then(next).catch(next)
})

`

panstromek avatar Jul 10 '18 16:07 panstromek

Thanks for reporting. Can you also post the component that does the redirect pls?

rstoenescu avatar Jul 10 '18 16:07 rstoenescu

Ok, I found out that another route crashes, too. Problem is that these routes doesn't have components attached to them.

panstromek avatar Jul 10 '18 16:07 panstromek

these are the routes. If I go to child '', it crashes


{
          path: 'tree',
          component: () => import('pages/TreePage'),
          beforeEnter: function (from, to, next) {
            requireLogin(from, to, next)
          },
          children: [
            {
              path: '',
              beforeEnter: function (from, to, next) {
                if (store.state.treeState.categoryId) {
                  next('/app/tree/' + store.state.treeState.categoryId)
                }
                else {next()}
              }
            },
            {
              path: ':id',
              props: route => ({id: Math.round(Number(route.params.id))}),
              component: () => import('components/tree/TreeView')
            }
          ]
        },

panstromek avatar Jul 10 '18 16:07 panstromek

Would it be hard for you if you could create a minimal reproduction repo? It would help me fix this much faster.

rstoenescu avatar Jul 10 '18 16:07 rstoenescu

Ok, I'll try.

panstromek avatar Jul 10 '18 16:07 panstromek

here is the reproduction link, try to go to /#/index/ route

https://github.com/panstromek/quasar-bug-reproduction

panstromek avatar Jul 10 '18 18:07 panstromek

I can't understand what you said? So what can we use it?

1083970440 avatar Jul 11 '18 14:07 1083970440

@1083970440 Sorry, I don't understand what you mean...

panstromek avatar Jul 11 '18 18:07 panstromek

fixed by 0.18 beta

panstromek avatar Jul 12 '18 18:07 panstromek