修改登录跳转逻辑: 自动返回上一页
This commit is contained in:
parent
83bd01fb79
commit
a59bf199d5
@ -40,10 +40,10 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import {ref} from 'vue'
|
||||
import {ref, onMounted} from 'vue'
|
||||
import swal from "../utils/sweetalert.js";
|
||||
import store from "../store/index.js";
|
||||
import router from "../router/index.js";
|
||||
import router, {getPreviousRoute} from "../router/index.js";
|
||||
import AuthService from "../../services/auth.js";
|
||||
|
||||
const mode = ref('login')
|
||||
@ -96,7 +96,7 @@ const handleLogin = async () => {
|
||||
loginInfo.value.isFinish = true;
|
||||
setTimeout(() => {
|
||||
if (router.currentRoute.value.path === '/login') {
|
||||
router.push('/');
|
||||
router.push(getPreviousRoute().path);
|
||||
}
|
||||
}, 2000);
|
||||
}
|
||||
@ -136,6 +136,10 @@ const handleRegister = async () => {
|
||||
store.commit('stopLoading');
|
||||
swal.window('info', '邮箱验证链接发送成功!', '请前往邮箱查看', '好的', 'ok');
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
console.log(getPreviousRoute())
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
@ -145,7 +145,9 @@ const router = createRouter({
|
||||
routes
|
||||
});
|
||||
|
||||
let previousRoute = null
|
||||
router.beforeEach(async (to, from, next) => {
|
||||
previousRoute = from;
|
||||
if (!store.state.userInfo.uid && store.state.token) {
|
||||
AuthService.setSelfInfo();
|
||||
}
|
||||
@ -182,5 +184,8 @@ router.beforeEach(async (to, from, next) => {
|
||||
|
||||
next();
|
||||
});
|
||||
export function getPreviousRoute() {
|
||||
return previousRoute
|
||||
}
|
||||
|
||||
export default router;
|
Loading…
x
Reference in New Issue
Block a user