【问题标题】:I need redirect before load page and show html elements我需要在加载页面之前重定向并显示 html 元素
【发布时间】:2021-08-20 07:25:35
【问题描述】:

我使用此代码进行重定向

beforeCreate() {
  if (this.$store.state.user.user.id != null) {
    this.$router.push('/')
  }
}

我的 this.$store.state.user.user.id 在中间件中用这个代码赋值。

import {GET_CARD, GET_USER} from "../store/types/action-types";
export default async function ({store}) {
  await store.dispatch('cart/' + GET_CARD)
  await store.dispatch('user/user/' + GET_USER)
}

如果用户登录显示页面 0.5 秒和下一个重定向。我不需要显示登录页面和下一个重定向。 tnx。

【问题讨论】:

    标签: nuxt.js


    【解决方案1】:

    此答案可能对您有所帮助:https://stackoverflow.com/a/68858238/8816585(几分钟前发布)

    这种中间件应该可以工作

    export default ({ store, redirect }) => {
      if (store.state.user.user.id) {
        redirect({ name: 'index' }) // or redirect('/')
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-05-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-03
      • 2012-03-24
      相关资源
      最近更新 更多