|
@@ -5,7 +5,7 @@
|
|
|
* 我这里应为大部分都可以随便进入,所以使用黑名单
|
|
* 我这里应为大部分都可以随便进入,所以使用黑名单
|
|
|
*/
|
|
*/
|
|
|
import { useUserStore } from '@/store'
|
|
import { useUserStore } from '@/store'
|
|
|
-import { needLoginPages as _needLoginPages, getNeedLoginPages } from '@/utils'
|
|
|
|
|
|
|
+import { needLoginPages as _needLoginPages, getNeedLoginPages, getLastPage } from '@/utils'
|
|
|
|
|
|
|
|
// TODO Check
|
|
// TODO Check
|
|
|
const loginRoute = '/pages/login/index'
|
|
const loginRoute = '/pages/login/index'
|
|
@@ -20,9 +20,19 @@ const isDev = import.meta.env.DEV
|
|
|
// 黑名单登录拦截器 - (适用于大部分页面不需要登录,少部分页面需要登录)
|
|
// 黑名单登录拦截器 - (适用于大部分页面不需要登录,少部分页面需要登录)
|
|
|
const navigateToInterceptor = {
|
|
const navigateToInterceptor = {
|
|
|
// 注意,这里的url是 '/' 开头的,如 '/pages/index/index',跟 'pages.json' 里面的 path 不同
|
|
// 注意,这里的url是 '/' 开头的,如 '/pages/index/index',跟 'pages.json' 里面的 path 不同
|
|
|
|
|
+ // 增加对相对路径的处理,BY 网友 @ideal
|
|
|
invoke({ url }: { url: string }) {
|
|
invoke({ url }: { url: string }) {
|
|
|
// console.log(url) // /pages/route-interceptor/index?name=feige&age=30
|
|
// console.log(url) // /pages/route-interceptor/index?name=feige&age=30
|
|
|
- const path = url.split('?')[0]
|
|
|
|
|
|
|
+ let path = url.split('?')[0]
|
|
|
|
|
+
|
|
|
|
|
+ // 处理相对路径
|
|
|
|
|
+ if (!path.startsWith('/')) {
|
|
|
|
|
+ const currentPath = getLastPage().route
|
|
|
|
|
+ const normalizedCurrentPath = currentPath.startsWith('/') ? currentPath : `/${currentPath}`
|
|
|
|
|
+ const baseDir = normalizedCurrentPath.substring(0, normalizedCurrentPath.lastIndexOf('/'))
|
|
|
|
|
+ path = `${baseDir}/${path}`
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
let needLoginPages: string[] = []
|
|
let needLoginPages: string[] = []
|
|
|
// 为了防止开发时出现BUG,这里每次都获取一下。生产环境可以移到函数外,性能更好
|
|
// 为了防止开发时出现BUG,这里每次都获取一下。生产环境可以移到函数外,性能更好
|
|
|
if (isDev) {
|
|
if (isDev) {
|