21 lines
500 B
TypeScript
21 lines
500 B
TypeScript
/**
|
|
* 链接解析:区分外部 URL 与站内路由
|
|
*
|
|
* 站内路由自动加当前语言前缀(中文无前缀,英文 /en 前缀)。
|
|
*/
|
|
export function useLinkResolver() {
|
|
const localePath = useLocalePath();
|
|
|
|
function isExternal(link: string): boolean {
|
|
return /^https?:\/\//.test(link);
|
|
}
|
|
|
|
function resolveLink(link: string): string {
|
|
if (!link) return '';
|
|
if (isExternal(link)) return link;
|
|
return localePath(link);
|
|
}
|
|
|
|
return { isExternal, resolveLink };
|
|
}
|