【发布时间】:2020-07-02 14:07:57
【问题描述】:
我正在使用 Nuxt,并且我创建了一个动态路由,该路由使用 vuex 和 axios 调用获取数据。当没有指定 id 参数时,我想将用户路由回index。我看到我可以在动态路由上使用validate https://nuxtjs.org/api/pages-validateWhen
我正在使用下面的代码,当我导航到 localhost:3000/settings/ 时,我收到以下错误 Cannot read property 'push' of undefined
页面/设置/_id.vue
export default {
validate({ params }) {
if (params.id !== null) {
this.$router.push({ name: 'index' })
}
return false
}
}
【问题讨论】: