美文网首页
2019-08-01 登录页面拦截及返回 登录前页面

2019-08-01 登录页面拦截及返回 登录前页面

作者: 半眼鱼 | 来源:发表于2019-08-01 10:45 被阅读0次

    1、在router.js 文件的meta内设定哪个页面是要登录的

      {
        path: '/order',
        name: 'cart',
        meta: {
          login: true
        },
        components: { 
          default: () => import('@/views/order/tabbar-cart'), 
          tabbar: Tabbar 
        }
      },
    

    2.在路由卫士进行拦截判断页面是否登录

    RouterModel.beforeEach((to, from, next) => {
      const { Authorization } = getLocalStorage(
        'Authorization'
      );
      if (!Authorization) {
        if (to.meta.login) {
          next({ name: 'login', query: { redirect: to.name } });
          return;
        }
      }
      next();
    });
    

    3.在登录页面设置数据请求回来后,返回原来的页面

     routerRedirect() {
          const { query } = this.$route;
          this.$router.replace({
            name: query.redirect || 'home',
            query: query
          });
          // window.location = '#/user/';
        },
    

    相关文章

      网友评论

          本文标题:2019-08-01 登录页面拦截及返回 登录前页面

          本文链接:https://www.haomeiwen.com/subject/qcxqdctx.html