[0.17 beta] "Cannot read property 'asyncData' of undefined" in route with no components
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
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
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)
})
`
Thanks for reporting. Can you also post the component that does the redirect pls?
Ok, I found out that another route crashes, too. Problem is that these routes doesn't have components attached to them.
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')
}
]
},
Would it be hard for you if you could create a minimal reproduction repo? It would help me fix this much faster.
Ok, I'll try.
here is the reproduction link, try to go to /#/index/ route
https://github.com/panstromek/quasar-bug-reproduction
I can't understand what you said? So what can we use it?
@1083970440 Sorry, I don't understand what you mean...
fixed by 0.18 beta