From 71c0de151c85c8885952abecffcf6948aa7dcaec Mon Sep 17 00:00:00 2001
From: h_mo <596417202@qq.com>
Date: Mon, 1 May 2023 00:31:12 +0800
Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BD=BF=E7=94=A8uni-mini-router?=
=?UTF-8?q?=E8=B7=AF=E7=94=B1=E7=AE=A1=E7=90=86?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
package.json | 2 +
src/App.vue | 7 --
src/components/Navbar/index.vue | 2 +-
src/hooks/router.ts | 44 ------------
src/main.ts | 6 +-
src/pages.json | 13 ++--
src/pages/about/index.vue | 2 +-
src/pages/demo/index.vue | 5 +-
src/pages/index/index.vue | 5 +-
src/pages/login/index.vue | 12 ++--
src/pages/notFound/404.vue | 6 +-
src/pagesA/list/test1/index.vue | 2 +-
src/pagesA/list/test2/index.vue | 2 +-
src/router/guard.ts | 39 ++++++++++
src/router/index.ts | 19 +++++
src/state/modules/router.ts | 35 ---------
src/types.d.ts | 2 +
src/types/router/route.d.ts | 32 ---------
src/utils/router/constant.ts | 38 ----------
src/utils/router/interceptor.ts | 75 -------------------
src/utils/router/navigates.ts | 123 --------------------------------
src/utils/router/routes.ts | 41 -----------
vite.config.ts | 2 +
23 files changed, 94 insertions(+), 420 deletions(-)
delete mode 100644 src/hooks/router.ts
create mode 100644 src/router/guard.ts
create mode 100644 src/router/index.ts
delete mode 100644 src/state/modules/router.ts
create mode 100644 src/types.d.ts
delete mode 100644 src/types/router/route.d.ts
delete mode 100644 src/utils/router/constant.ts
delete mode 100644 src/utils/router/interceptor.ts
delete mode 100644 src/utils/router/navigates.ts
delete mode 100644 src/utils/router/routes.ts
diff --git a/package.json b/package.json
index 64d8332..09e004f 100644
--- a/package.json
+++ b/package.json
@@ -60,6 +60,7 @@
"lodash-es": "^4.17.21",
"pinia": "^2.0.35",
"qs": "^6.11.1",
+ "uni-read-pages-vite": "^0.0.5",
"vue": "^3.2.47"
},
"devDependencies": {
@@ -87,6 +88,7 @@
"prettier": "^2.8.8",
"sass": "^1.62.1",
"typescript": "^5.0.4",
+ "uni-mini-router": "^0.0.7",
"unocss": "^0.46.5",
"unocss-preset-weapp": "^0.2.5",
"vite": "^4.3.2",
diff --git a/src/App.vue b/src/App.vue
index 1ae0729..610e6eb 100644
--- a/src/App.vue
+++ b/src/App.vue
@@ -1,15 +1,8 @@
diff --git a/src/pages/index/index.vue b/src/pages/index/index.vue
index 6e9a83c..cd7cb61 100644
--- a/src/pages/index/index.vue
+++ b/src/pages/index/index.vue
@@ -2,7 +2,7 @@
import { ref } from 'vue';
import BasicButton from '@/components/BasicButton/index.vue';
import AppProvider from '@/components/AppProvider/inedx.vue';
-import { useRouter } from '@/hooks/router';
+import { useRouter } from 'uni-mini-router';
import { CURRENT_PLATFORM, PLATFORMS } from '@/enums/platformEnum';
import { judgePlatform } from '@/utils/platform';
import Iconify from '@/components/Iconify/index.vue';
@@ -18,8 +18,7 @@ const isVue3 = judgePlatform(PLATFORMS.VUE3);
const router = useRouter();
const handleGetStarted = () => {
- router.pushTab('/pages/demo/index');
- // router.push('/pages/log/index?id=4345&title=log');
+ router.pushTab({ path: '/pages/demo/index' });
};
diff --git a/src/pages/login/index.vue b/src/pages/login/index.vue
index ee8e084..21ad218 100644
--- a/src/pages/login/index.vue
+++ b/src/pages/login/index.vue
@@ -3,7 +3,7 @@ import { reactive, ref } from 'vue';
import { onLoad } from '@dcloudio/uni-app';
import { useAuthStore } from '@/state/modules/auth';
import { Toast } from '@/utils/uniapi/prompt';
-import { useRouter } from '@/hooks/router';
+import { useRouter } from 'uni-mini-router';
import { useRequest } from 'alova';
import { login } from '@/services/api/auth';
@@ -25,11 +25,11 @@ const submit = (e: any) => {
Toast('登录成功', { duration: 1500 });
authStore.setToken(res.token);
setTimeout(() => {
- if (redirect.value) {
- router.go(redirect.value!, { replace: true });
- return;
- }
- router.pushTab('/pages/about/index');
+ // if (redirect.value) {
+ // router.push(redirect.value!, { replace: true });
+ // return;
+ // }
+ router.replaceAll({ name: 'Home' });
}, 1500);
});
};
diff --git a/src/pages/notFound/404.vue b/src/pages/notFound/404.vue
index c66df18..aa1909c 100644
--- a/src/pages/notFound/404.vue
+++ b/src/pages/notFound/404.vue
@@ -2,14 +2,14 @@
import { onLoad } from '@dcloudio/uni-app';
import { ref } from 'vue';
import BasicButton from '@/components/BasicButton/index.vue';
-import { useRouter } from '@/hooks/router';
+import { useRouter } from 'uni-mini-router';
const go = ref('');
const router = useRouter();
const redirect = ref('');
onLoad((query) => {
- go.value = query.go || '';
- redirect.value = query.redirect || '';
+ go.value = query?.go || '';
+ redirect.value = query?.redirect || '';
});
/**
diff --git a/src/pagesA/list/test1/index.vue b/src/pagesA/list/test1/index.vue
index bcaa727..ad87a28 100644
--- a/src/pagesA/list/test1/index.vue
+++ b/src/pagesA/list/test1/index.vue
@@ -1,6 +1,6 @@