mirror of
https://github.com/Tencent/tdesign-vue-next-starter.git
synced 2024-09-19 18:24:20 +08:00
feat: 优化登录跳转支持回跳带query参数的页面 (#374)
This commit is contained in:
parent
6ccc3279f9
commit
6cd9fe9134
|
@ -143,7 +143,10 @@ const handleNav = (url) => {
|
|||
};
|
||||
|
||||
const handleLogout = () => {
|
||||
router.push(`/login?redirect=${router.currentRoute.value.fullPath}`);
|
||||
router.push({
|
||||
path: '/login',
|
||||
query: { redirect: encodeURIComponent(router.currentRoute.value.fullPath) },
|
||||
});
|
||||
};
|
||||
|
||||
const navToGitHub = () => {
|
||||
|
|
|
@ -80,7 +80,7 @@
|
|||
|
||||
<script setup lang="ts">
|
||||
import { ref } from 'vue';
|
||||
import { useRouter } from 'vue-router';
|
||||
import { useRoute, useRouter } from 'vue-router';
|
||||
import QrcodeVue from 'qrcode.vue';
|
||||
import { FormInstanceFunctions, MessagePlugin } from 'tdesign-vue-next';
|
||||
import { useCounter } from '@/hooks';
|
||||
|
@ -116,6 +116,7 @@ const switchType = (val: string) => {
|
|||
};
|
||||
|
||||
const router = useRouter();
|
||||
const route = useRoute();
|
||||
|
||||
/**
|
||||
* 发送验证码
|
||||
|
@ -134,9 +135,9 @@ const onSubmit = async ({ validateResult }) => {
|
|||
await userStore.login(formData.value);
|
||||
|
||||
MessagePlugin.success('登陆成功');
|
||||
router.push({
|
||||
path: '/dashboard/base',
|
||||
});
|
||||
const redirect = route.query.redirect as string;
|
||||
const redirectUrl = redirect ? decodeURIComponent(redirect) : '/dashboard';
|
||||
router.push(redirectUrl);
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
MessagePlugin.error(e.message);
|
||||
|
|
|
@ -40,7 +40,10 @@ router.beforeEach(async (to, from, next) => {
|
|||
}
|
||||
} catch (error) {
|
||||
MessagePlugin.error(error);
|
||||
next(`/login?redirect=${to.path}`);
|
||||
next({
|
||||
path: '/login',
|
||||
query: { redirect: encodeURIComponent(to.fullPath) },
|
||||
});
|
||||
NProgress.done();
|
||||
}
|
||||
}
|
||||
|
@ -49,7 +52,10 @@ router.beforeEach(async (to, from, next) => {
|
|||
if (whiteListRouters.indexOf(to.path) !== -1) {
|
||||
next();
|
||||
} else {
|
||||
next(`/login?redirect=${to.path}`);
|
||||
next({
|
||||
path: '/login',
|
||||
query: { redirect: encodeURIComponent(to.fullPath) },
|
||||
});
|
||||
}
|
||||
NProgress.done();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user