1.新增描述文档
This commit is contained in:
@@ -16,10 +16,11 @@
|
||||
*/
|
||||
import { AppRouteRecord } from '@/types/router'
|
||||
import { router } from '@/router'
|
||||
import { resolveAppAssetUrl } from '@/utils/navigation/resolveAppAssetUrl'
|
||||
|
||||
// 打开外部链接
|
||||
// 打开外部链接(含站内静态页,自动拼接部署 base)
|
||||
export const openExternalLink = (link: string) => {
|
||||
window.open(link, '_blank')
|
||||
window.open(resolveAppAssetUrl(link), '_blank', 'noopener,noreferrer')
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
19
saiadmin-artd/src/utils/navigation/resolveAppAssetUrl.ts
Normal file
19
saiadmin-artd/src/utils/navigation/resolveAppAssetUrl.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
/**
|
||||
* 解析菜单外链 / 静态资源路径(兼容 VITE_BASE_URL 子目录部署)
|
||||
*/
|
||||
export function resolveAppAssetUrl(relativeOrAbsolute: string): string {
|
||||
const link = relativeOrAbsolute.trim()
|
||||
if (!link) {
|
||||
return link
|
||||
}
|
||||
if (/^https?:\/\//i.test(link)) {
|
||||
return link
|
||||
}
|
||||
const base = import.meta.env.BASE_URL || '/'
|
||||
const normalizedBase = base.endsWith('/') ? base : `${base}/`
|
||||
const path = link.startsWith('/') ? link.slice(1) : link
|
||||
if (typeof window === 'undefined') {
|
||||
return `${normalizedBase}${path}`
|
||||
}
|
||||
return `${window.location.origin}${normalizedBase}${path}`
|
||||
}
|
||||
Reference in New Issue
Block a user