【问题标题】:how to redirect from one url to another in vue如何在vue中从一个url重定向到另一个url
【发布时间】:2018-08-06 11:32:49
【问题描述】:

我正在尝试使用 Vue 路由器(例如代码)从一个 URL 重定向到另一个 URL

  {
    path: '/verifyemail/:id/:token',
  //can i somelogic here when user entered 
  },
  {
    path: '/login',
    component:login

  },

我想做什么?当用户注册自己时。当用户从他的电子邮件中单击验证按钮时,服务器将电子邮件验证链接发送到他的电子邮件,然后它应该首先调用 verifyemail url。它有一个带有参数的ajax调用,我现在从verifyemail url获取成功后它应该移动到登录url 注意:-我的verfiyemail路由中没有任何组件 是否有可能做到这一点或有任何其他方式来实现这一点

【问题讨论】:

    标签: vue.js vue-router


    【解决方案1】:

    路由配置只是数据,因此实际上没有任何方法可以完全按照您的意愿执行此操作。

    如果您创建一个组件来处理/verifyemail/ 路由,您可以在其中使用this.$router.push(redirectToMe)。请参阅Vue Router docs 了解更多信息。

    另外,这听起来更像是后端服务器自己处理的事情,所以也许你甚至不需要 Vue 来担心它。

    【讨论】:

    • 很高兴看到您提出了更好的解决方案!
    【解决方案2】:

    最后,我得到了一个解决方案,这可能是对其他的帮助

    开始吧,我发送带有验证按钮的电子邮件,该按钮具有类似“localhost:8080/#/verfiyemail/("ACCESSTOKEN")”之类的链接现在我的 vue 部分我做了类似的事情 在 vue-route 中

    path: '/verifyemail/:uid',
    beforeEnter:(to, from, next) => {
                        let uid=to.params.uid;
                        next({ path: '/', query: { id: uid}})
            }
    },
    
    {
      path: '/',
      name: 'Login',
      component: Login,
    },
    

    我的 login.vue

    created(){
           this.verfiyemai();
      },
    methods:{
      verfiyemai(){
           var _this=this
           var submit=0
    
           if(this.$route.query.id!=undefined ){
    
               if(this.$route.query.id.length<=50){
                   this.$router.push('/');
                     submit=1;
                }
    
            if(submit==0){
                    this.$http.get('/api/users/confirm?uid='+this.$route.query.id+'')
                 .then(function (response) {
                      console.log(response)
                    })
                 .catch(function (error) {
                   console.log(error)
                     });
    
                }
    
    
            }
    
         },
    
    }
    

    从电子邮件中,我将用户重定向到 verfiyemail,并将令牌 ID 作为参数从 verifyemail 路由中重定向到登录 URL,并将参数作为查询传递,并且在我的登录 vue 中,我创建了一个检查查询长度的方法,如果大于 50 就会向服务器发送 axios 响应

    【讨论】:

      猜你喜欢
      • 2023-03-20
      • 2015-12-29
      • 2013-03-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-10
      • 1970-01-01
      相关资源
      最近更新 更多