diff --git a/src/router/README.md b/src/router/README.md index 3854a85..82dbdb3 100644 --- a/src/router/README.md +++ b/src/router/README.md @@ -22,6 +22,24 @@ 在 `默认需要登录策略: DEFAULT_NEED_LOGIN` 中,只有路由在 `EXCLUDE_LOGIN_PATH_LIST` 中,才不需要登录,相当于白名单。 +### excludeLoginPath +definePage 中可以通过 `excludeLoginPath` 来配置路由是否需要登录。(类似过去的 needLogin 的功能) + +```ts +definePage({ + style: { + navigationBarTitleText: '关于', + }, + // 登录授权(可选):跟以前的 needLogin 类似功能,但是同时支持黑白名单,详情请见 arc/router 文件夹 + excludeLoginPath: true, + // 角色授权(可选):如果需要根据角色授权,就配置这个 + roleAuth: { + field: 'role', + value: 'admin', + redirect: '/pages/auth/403', + }, +}) +``` ## 登录注册页路由 diff --git a/src/router/interceptor.ts b/src/router/interceptor.ts index 249b084..4291fa5 100644 --- a/src/router/interceptor.ts +++ b/src/router/interceptor.ts @@ -8,16 +8,16 @@ import { isPageTabbar, tabbarStore } from '@/tabbar/store' import { getAllPages, getLastPage, parseUrlToObj } from '@/utils/index' import { EXCLUDE_LOGIN_PATH_LIST, HOME_PAGE, isNeedLoginMode, LOGIN_PAGE } from './config' -const isDev = import.meta.env.DEV export const FG_LOG_ENABLE = false export function judgeIsExcludePath(path: string) { + const isDev = import.meta.env.DEV if (!isDev) { return EXCLUDE_LOGIN_PATH_LIST.includes(path) } const allExcludeLoginPages = getAllPages('excludeLoginPath') // dev 环境下,需要每次都重新获取,否则新配置就不会生效 return EXCLUDE_LOGIN_PATH_LIST.includes(path) || (isDev && allExcludeLoginPages.some(page => page.path === path)) } -// 黑名单登录拦截器 - (适用于大部分页面不需要登录,少部分页面需要登录) + export const navigateToInterceptor = { // 注意,这里的url是 '/' 开头的,如 '/pages/index/index',跟 'pages.json' 里面的 path 不同 // 增加对相对路径的处理,BY 网友 @ideal