Skip to content

Commit f74fe7b

Browse files
authored
feat: 支持登录重定向 (#258)
1 parent a05c64d commit f74fe7b

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/pages/login/index.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import { getCaptchaApi, loginApi } from "./apis"
99
import Owl from "./components/Owl.vue"
1010
import { useFocus } from "./composables/useFocus"
1111
12+
const route = useRoute()
13+
1214
const router = useRouter()
1315
1416
const userStore = useUserStore()
@@ -57,7 +59,7 @@ function handleLogin() {
5759
loading.value = true
5860
loginApi(loginFormData).then(({ data }) => {
5961
userStore.setToken(data.token)
60-
router.push("/")
62+
router.push(route.query.redirect ? decodeURIComponent(route.query.redirect as string) : "/")
6163
}).catch(() => {
6264
createCode()
6365
loginFormData.password = ""

src/router/guard.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export function registerNavigationGuard(router: Router) {
2525
// 如果在免登录的白名单中,则直接进入
2626
if (isWhiteList(to)) return true
2727
// 其他没有访问权限的页面将被重定向到登录页面
28-
return LOGIN_PATH
28+
return `${LOGIN_PATH}?redirect=${encodeURIComponent(to.fullPath)}`
2929
}
3030
// 如果已经登录,并准备进入 Login 页面,则重定向到主页
3131
if (to.path === LOGIN_PATH) return "/"

0 commit comments

Comments
 (0)