vueでのルーティングフロントガード

1274 ワード

router.beforeEach((to, from, next) => {
    const name = sessionStorage.getItem("username");
    const token = sessionStorage.getItem("xb-token");
    console.log(to.name)
    if(to.name == 'PrescriptionHomepage'){
        $('.home-main').css({"background": "#000000"});
    }else{
        $('.home-main').css({"background": "#eef3f9"});
    }
    if (to.name === 'Login' || to.name === 'Register' || to.name === 'RegistrationAgreement' || to.name =='SignatureAgreement') {
        next();
    } else {
        if (token) {
            if (name) {
                next();
            } else {
                router.push("/xb-login")
            }
        } else {
            Message.warning('    ');
            router.push("/xb-login");
        }
    }
});

//to.name:       name  ,       ,    name    。  :
this.$router.push({
    name: "ChangePrescription",
    // query: {
    //     id: id,
    // }
 });
this.$router.push('/xb-home/xb-security/personalInformation');       .name   。
//      to.path                。  :
this.$router.push('/xb-home/xb-security/personalInformation');