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