소스 검색

登录页如果没有params参数,则路径中不显示params

yanglzh 3 년 전
부모
커밋
a07a5ee168
2개의 변경된 파일7개의 추가작업 그리고 2개의 파일을 삭제
  1. 6 1
      src/router/index.ts
  2. 1 1
      src/views/login/component/account.vue

+ 6 - 1
src/router/index.ts

@@ -220,7 +220,12 @@ router.beforeEach(async (to, from, next) => {
 		NProgress.done();
 	} else {
 		if (!token) {
-			next(`/login?redirect=${to.path}&params=${JSON.stringify(to.query ? to.query : to.params)}`);
+			const params = Object.keys(to.query).length || Object.keys(to.params).length
+			let paramsStr = ''
+			if (params) {
+				paramsStr = `&params=${JSON.stringify(Object.keys(to.query).length ? to.query : to.params)}`
+			}
+			next(`/login?redirect=${to.path}${paramsStr}`);
 			Session.clear();
 			resetRoute();
 			NProgress.done();

+ 1 - 1
src/views/login/component/account.vue

@@ -160,7 +160,7 @@ export default defineComponent({
 			if (route.query?.redirect) {
 				router.push({
 					path: route.query?.redirect as string,
-					query: Object.keys(route.query?.params as string).length > 0 ? JSON.parse(route.query?.params as string) : '',
+					query: route.query.params ? (Object.keys(route.query?.params as string).length > 0 ? JSON.parse(route.query?.params as string) : '') : '',
 				});
 			} else {
 				router.push('/');